├── .github
└── workflows
│ ├── README.md
│ ├── prebuild.yml
│ ├── publish.yml
│ └── test.yml
├── .gitignore
├── .gitmodules
├── LICENSE
├── Makefile
├── README.md
├── bench.js
├── binding-src
├── binding-util
│ ├── napi-ingress.cc
│ └── napi-ingress.h
├── binding.cc
└── binding
│ ├── napi-hdr_histogram.cc
│ └── napi-hdr_histogram.h
├── binding.gyp
├── histogram.js
├── package.json
├── scripts
├── README.md
├── publish-github.sh
└── publish-local.sh
├── test.js
└── zlib
├── CMakeLists.txt
├── ChangeLog
├── FAQ
├── INDEX
├── Makefile
├── Makefile.in
├── README
├── adler32.c
├── compress.c
├── configure
├── crc32.c
├── crc32.h
├── deflate.c
├── deflate.h
├── gzclose.c
├── gzguts.h
├── gzlib.c
├── gzread.c
├── gzwrite.c
├── infback.c
├── inffast.c
├── inffast.h
├── inffixed.h
├── inflate.c
├── inflate.h
├── inftrees.c
├── inftrees.h
├── make_vms.com
├── treebuild.xml
├── trees.c
├── trees.h
├── uncompr.c
├── zconf.h
├── zconf.h.cmakein
├── zconf.h.in
├── zlib.3
├── zlib.3.pdf
├── zlib.gyp
├── zlib.h
├── zlib.map
├── zlib.pc.cmakein
├── zlib.pc.in
├── zlib2ansi
├── zutil.c
└── zutil.h
/.github/workflows/README.md:
--------------------------------------------------------------------------------
1 | ## About these GitHub workflows
2 |
3 | ### prebuild.yml
4 |
5 | This GitHub workflow runs each time a new tag is pushed to the repository.
6 |
7 | The workflow builds binaries for each supported operating system and platform. The binaries are uploaded to a new release in the the GitHub repository. These binaries are later downloaded from the GitHub release as part of the process of publishing the npm module.
8 |
9 | The process of publishing the native addon to npm should not be performed until this GitHub workflow runs successfully to completion and the results are verified.
10 |
11 | ### publish.yml
12 |
13 | This GitHub workflow runs when an authenticated `POST` is made to the GitHub API `/dispatches` endpoint.
14 |
15 | The workflow downloads the binaries from the GitHub release created by the prebuild process and publishes the native addon as an npm module.
16 |
17 | This workflow has the following requirements:
18 |
19 | - The settings of the GitHub repository where the workflow is running must include an `NPM_TOKEN` GitHub secret containing a valid npm authentication token for the npm account.
20 |
21 | - The token specified in the `NPM_TOKEN` GitHub secret must have the **Publish** capability.
22 |
23 | - If Two-Factor Authentication is enabled for the npm account where the module is being published, the "2FA Mode" must be for **Authorization** only and not for **Authorization and Publishing**.
24 |
25 | The `publish-github.sh` script in this project's `scripts` directory can be used to issue a correctly formatted `POST` to the GitHub API to trigger this workflow.
26 |
27 | ### test.yml
28 |
29 | This GitHub workflow runs on each push and pull request. It also runs each Sunday at 04:00 UTC.
30 |
31 | The workflow runs routine smoke tests on the code with the current and immediately previous Node.js LTS versions.
32 |
33 |
--------------------------------------------------------------------------------
/.github/workflows/prebuild.yml:
--------------------------------------------------------------------------------
1 | name: Prebuild Binaries
2 |
3 | on:
4 | push:
5 | tags:
6 | - v*
7 |
8 | env:
9 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 |
11 | jobs:
12 | create_release:
13 | name: Create Release
14 | runs-on: ubuntu-latest
15 | outputs:
16 | upload_url: ${{ steps.create_release.outputs.upload_url }}
17 | steps:
18 | - name: Create Release
19 | id: create_release
20 | uses: actions/create-release@v1
21 | with:
22 | tag_name: ${{ github.ref }}
23 | release_name: ${{ github.ref }}
24 | prerelease: true
25 | body: |
26 | The archive files in this release are not meant to be downloaded directly.
27 | Instead, the binaries are downloaded by prebuildify-ci and bundled into the npm module.
28 |
29 | prebuild:
30 | strategy:
31 | matrix:
32 | os: [ ubuntu-latest, macos-latest, windows-latest ]
33 |
34 | name: Prebuild ${{ matrix.os }}
35 | runs-on: ${{ matrix.os }}
36 | timeout-minutes: 20
37 | needs: create_release
38 |
39 | steps:
40 | - if: matrix.os == 'ubuntu-latest'
41 | name: Install Linux Toolchain
42 | run: sudo apt-get install g++-multilib
43 |
44 | - name: Checkout Code
45 | uses: actions/checkout@v2
46 | with:
47 | submodules: true
48 |
49 | - name: Install Node.js
50 | uses: actions/setup-node@v1
51 | with:
52 | node-version: 14.x
53 |
54 | - if: matrix.os != 'windows-latest'
55 | name: Set Archive Env Variables (Linux, macOS)
56 | run: |
57 | echo ::set-env name=ARCHIVE_NAME::${GITHUB_REF#refs/tags/}-${{ runner.os }}.tar
58 | echo ::set-env name=ARCHIVE_TYPE::application/tar
59 | - if: matrix.os == 'windows-latest'
60 | name: Set Archive Env Variables (Windows)
61 | run: |
62 | echo ::set-env name=ARCHIVE_NAME::${GITHUB_REF#refs/tags/}-${{ runner.os }}.zip
63 | echo ::set-env name=ARCHIVE_TYPE::application/zip
64 | shell: bash
65 |
66 | - name: Install
67 | run: npm install
68 |
69 | - name: Prebuild 64-bit # build 64-bit for each os
70 | run: npm run prebuild
71 |
72 | - if: matrix.os == 'ubuntu-latest' # linux only, no macOS 32-bit build
73 | name: Prebuild 32-bit (Linux)
74 | run: PREBUILD_ARCH=ia32 npm run prebuild
75 | - if: matrix.os == 'windows-latest' # windows only
76 | name: Prebuild 32-bit (Windows)
77 | run: |
78 | $env:PREBUILD_ARCH = "ia32"
79 | npm run prebuild
80 |
81 | - if: matrix.os != 'windows-latest'
82 | name: Archive Prebuilds (Linux, macOS)
83 | run: tar --create --verbose --file=${ARCHIVE_NAME} --directory ./prebuilds .
84 | - if: matrix.os == 'windows-latest'
85 | name: Archive Prebuilds (Windows)
86 | run: Compress-Archive -Path .\prebuilds\* -DestinationPath .\$env:ARCHIVE_NAME
87 |
88 | - name: Upload Archive to GitHub Release
89 | uses: actions/upload-release-asset@v1
90 | with:
91 | upload_url: ${{ needs.create_release.outputs.upload_url }}
92 | asset_path: ./${{ env.ARCHIVE_NAME }}
93 | asset_name: ${{ env.ARCHIVE_NAME }}
94 | asset_content_type: ${{ env.ARCHIVE_TYPE }}
95 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish to npm
2 |
3 | on:
4 | workflow_dispatch:
5 |
6 | jobs:
7 | publish:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - name: Checkout Code
11 | uses: actions/checkout@v2
12 | with:
13 | submodules: true
14 |
15 | - name: Install Node.js
16 | uses: actions/setup-node@v1
17 | with:
18 | node-version: '12.x'
19 | registry-url: 'https://registry.npmjs.org'
20 | - run: npm install
21 | - run: npx prebuildify-ci download
22 | - run: npm publish
23 | env:
24 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
25 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | push:
5 | pull_request:
6 | schedule:
7 | - cron: "0 4 * * 0"
8 |
9 | jobs:
10 | test:
11 | runs-on: ${{ matrix.os }}
12 |
13 | strategy:
14 | matrix:
15 | os: [ubuntu-latest, windows-latest, macos-latest]
16 | node-version: [12.x, 14.x]
17 |
18 | steps:
19 | - name: Checkout Code
20 | uses: actions/checkout@v2
21 | with:
22 | submodules: true
23 |
24 | - name: Install Node.js ${{ matrix.node-version }}
25 | uses: actions/setup-node@v1
26 | with:
27 | node-version: ${{ matrix.node-version }}
28 |
29 | - run: npm install
30 | - name: Environment Information
31 | run: npx envinfo
32 | - name: Run Test
33 | run: npm test
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18 | .grunt
19 |
20 | # node-waf configuration
21 | .lock-wscript
22 |
23 | # Compiled binary addons (http://nodejs.org/api/addons.html)
24 | build-tmp-napi-v3/
25 |
26 | # Dependency directory
27 | node_modules
28 |
29 | # Optional npm cache directory
30 | .npm
31 |
32 | # Optional REPL history
33 | .node_repl_history
34 | build/
35 | prebuilds/
36 |
37 | # zlib windows
38 | zlib/Release/
39 | zlib/zlib.sln
40 | zlib/zlib.vcxproj
41 | zlib/zlib.vcxproj.filters
42 | lib/binding
43 |
44 | yarn.lock
45 | package-lock.json
46 | .nyc_output
47 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "HdrHistogram_c"]
2 | path = HdrHistogram_c
3 | url = https://github.com/HdrHistogram/HdrHistogram_c.git
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | native-hdr-histogram license
2 |
3 | The MIT License (MIT)
4 |
5 | Copyright (c) 2016 Matteo Collina
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
25 | -----------------------------------------------------------------------------
26 |
27 | HdrHistogram_c license
28 |
29 | Copyright (c) 2012, 2013, 2014 Gil Tene
30 | Copyright (c) 2014 Michael Barker
31 | Copyright (c) 2014 Matt Warren
32 | All rights reserved.
33 |
34 | Redistribution and use in source and binary forms, with or without
35 | modification, are permitted provided that the following conditions are met:
36 |
37 | 1. Redistributions of source code must retain the above copyright notice,
38 | this list of conditions and the following disclaimer.
39 |
40 | 2. Redistributions in binary form must reproduce the above copyright notice,
41 | this list of conditions and the following disclaimer in the documentation
42 | and/or other materials provided with the distribution.
43 |
44 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
48 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 | THE POSSIBILITY OF SUCH DAMAGE.
55 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | #http://www.gnu.org/prep/standards/html_node/Standard-Targets.html#Standard-Targets
2 |
3 | all: build
4 |
5 | ./node_modules:
6 | npm install --build-from-source
7 |
8 | build: ./node_modules
9 | ./node_modules/.bin/node-pre-gyp build --loglevel=silent
10 |
11 | debug:
12 | ./node_modules/.bin/node-pre-gyp rebuild --debug
13 |
14 | verbose:
15 | ./node_modules/.bin/node-pre-gyp rebuild --loglevel=verbose
16 |
17 | clean:
18 | @rm -rf ./build
19 | rm -rf lib/binding/
20 | rm -f test/support/big.db-journal
21 | rm -rf ./node_modules/
22 |
23 | grind:
24 | valgrind --leak-check=full node node_modules/.bin/_mocha
25 |
26 | testpack:
27 | rm -f ./*tgz
28 | npm pack
29 | tar -ztvf *tgz
30 | rm -f ./*tgz
31 |
32 | rebuild:
33 | @make clean
34 | @make
35 |
36 | test:
37 | @PATH="./node_modules/.bin:${PATH}" && NODE_PATH="./lib:$(NODE_PATH)" standard && tap test.js
38 |
39 | check: test
40 |
41 | .PHONY: test clean build
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # native-hdr-histogram
2 |
3 | node.js bindings for [hdr histogram][hdr] [C implementation][cimpl] (version 0.11.1)
4 |
5 | 
6 | 
7 | [](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api)
8 |
9 | > HDR Histogram is designed for recoding histograms of value measurements
10 | in latency and performance sensitive applications. Measurements show
11 | value recording times as low as 3-6 nanoseconds on modern (circa 2014)
12 | Intel CPUs. A Histogram's memory footprint is constant, with no
13 | allocation operations involved in recording data values or in iterating through them.
14 | - from [hdr histogram][hdr] website
15 |
16 | This library is blazingly fast, and you can use it to record
17 | histograms with no overhead. Linux, Mac OS X and Windows are all
18 | supported.
19 |
20 | * Installation
21 | * Example
22 | * API
23 | * Licence & copyright
24 |
25 | ## Install
26 |
27 | ```bash
28 | npm i native-hdr-histogram --save
29 | ```
30 |
31 | If you see any errors, you might need to configure your system to compile native addons:
32 | follow the instructions at [node-gyp][node-gyp].
33 |
34 | ## Example
35 |
36 | ```js
37 | 'use strict'
38 |
39 | const Histogram = require('native-hdr-histogram')
40 | const max = 1000000
41 | const key = 'record*' + max
42 | const histogram = new Histogram(1, 100)
43 |
44 | console.time(key)
45 | for (let i = 0; i < max; i++) {
46 | histogram.record(Math.floor((Math.random() * 42 + 1)))
47 | }
48 | console.timeEnd(key)
49 |
50 | console.log('80 percentile is', histogram.percentile(80))
51 | console.log('99 percentile is', histogram.percentile(99))
52 |
53 | console.log(histogram.percentiles())
54 | ```
55 |
56 | ## API
57 |
58 | * Histogram
59 | * histogram#record()
60 | * histogram#recordCorrectedValue()
61 | * histogram#min()
62 | * histogram#max()
63 | * histogram#mean()
64 | * histogram#stddev()
65 | * histogram#percentile()
66 | * histogram#percentiles()
67 | * histogram#linearcounts()
68 | * histogram#logcounts()
69 | * histogram#recordedcounts()
70 | * histogram#encode()
71 | * histogram#decode()
72 | * histogram#lowestEquivalentValue()
73 | * histogram#highestEquivalentValue()
74 | * histogram#nextNonEquivalentValue()
75 | * histogram#areValuesEquivalent()
76 | * histogram#add()
77 | * histogram#reset()
78 |
79 | #### Properties
80 | * histogram#lowestTrackableValue
81 | * histogram#highestTrackableValue
82 | * histogram#significantFigures
83 | * histogram#totalCount
84 | * histogram#memorySize
85 |
86 | -------------------------------------------------------
87 |
88 |
89 | ### Histogram(lowest, max, figures)
90 |
91 | Create a new histogram with:
92 |
93 | * `lowest`: is the lowest possible number that can be recorded (default
94 | 1).
95 | * `max`: is the maximum number that can be recorded (default 100).
96 | * `figures`: the number of figures in a decimal number that will be
97 | maintained, must be between 1 and 5 (inclusive) (default 3).
98 |
99 | -------------------------------------------------------
100 |
101 |
102 | ### histogram.record(value, count = 1)
103 |
104 | Record `value` in the histogram with a count of `count`. Returns `true` if the recording was
105 | successful, `false` otherwise.
106 |
107 | -------------------------------------------------------
108 |
109 |
110 | ### histogram.recordCorrectedValue(value, expectedInterval, count = 1)
111 |
112 | Record `value` in the histogram with a count of `count` and backfill based on a `expectedInterval`.
113 | This is specifically used for recording latency. If `value` is larger than the `expectedInterval`
114 | then the latency recording system has experienced coordinated omission. This method fills in the
115 | values that would have occurred had the client providing the load not been blocked.
116 |
117 | Returns `true` if the recording was successful, `false` otherwise.
118 |
119 | -------------------------------------------------------
120 |
121 |
122 | ### histogram.min()
123 |
124 | Return the minimum value recorded in the histogram.
125 |
126 | -------------------------------------------------------
127 |
128 |
129 | ### histogram.max()
130 |
131 | Return the maximum value recorded in the histogram.
132 |
133 | -------------------------------------------------------
134 |
135 |
136 | ### histogram.mean()
137 |
138 | Return the mean of the histogram.
139 |
140 | -------------------------------------------------------
141 |
142 |
143 | ### histogram.stddev()
144 |
145 | Return the standard deviation of the histogram.
146 |
147 | -------------------------------------------------------
148 |
149 |
150 | ### histogram.percentile(percentile)
151 |
152 | Returns the value at the given percentile. `percentile` must be >
153 | 0 and <= 100, otherwise it will throw.
154 |
155 | -------------------------------------------------------
156 |
157 |
158 | ### histogram.percentiles()
159 |
160 | Returns all the percentiles.
161 |
162 | Sample output:
163 |
164 | ```js
165 | [ { percentile: 0, value: 1 },
166 | { percentile: 50, value: 22 },
167 | { percentile: 75, value: 32 },
168 | { percentile: 87.5, value: 37 },
169 | { percentile: 93.75, value: 40 },
170 | { percentile: 96.875, value: 41 },
171 | { percentile: 98.4375, value: 42 },
172 | { percentile: 100, value: 42 } ]
173 | ```
174 |
175 | -------------------------------------------------------
176 |
177 |
178 | ### histogram.linearcounts(valueUnitsPerBucket)
179 |
180 | Returns the recorded counts in "buckets" using `valueUnitsPerBucket` as the bucket size.
181 |
182 | Sample output:
183 |
184 | ```js
185 | [
186 | { count: 10000, value: 99968 },
187 | { count: 0, value: 199936 },
188 | { count: 0, value: 299776 },
189 | { count: 0, value: 399872 },
190 | { count: 0, value: 499968 },
191 | { count: 0, value: 599552 },
192 | { count: 0, value: 699904 },
193 | { count: 0, value: 799744 },
194 | { count: 0, value: 899584 },
195 | { count: 0, value: 999936 },
196 | ... 990 more items
197 | ]
198 | ```
199 | -------------------------------------------------------
200 |
201 |
202 | ### histogram.logcounts(valueUnitsFirstBucket, logBase)
203 |
204 | Returns the recorded counts according to a logarithmic distribution using `valueUnitsFirstBucket`
205 | for the first value and increasing exponentially according to `logBase`.
206 |
207 | Sample output:
208 |
209 | ```js
210 | [
211 | { count: 10000, value: 10000 },
212 | { count: 0, value: 20000 },
213 | { count: 0, value: 40000 },
214 | { count: 0, value: 80000 },
215 | { count: 0, value: 160000 },
216 | { count: 0, value: 320000 },
217 | { count: 0, value: 640000 },
218 | { count: 0, value: 1280000 },
219 | { count: 0, value: 2560000 },
220 | { count: 0, value: 5120000 },
221 | { count: 0, value: 10240000 },
222 | { count: 0, value: 20480000 },
223 | { count: 0, value: 40960000 },
224 | { count: 0, value: 81920000 },
225 | { count: 1, value: 163840000 }
226 | ]
227 | ```
228 |
229 | -------------------------------------------------------
230 |
231 |
232 | ### histogram.recordedcounts()
233 |
234 | Returns all the values recorded in the histogram.
235 |
236 | Sample output:
237 |
238 | ```js
239 | [
240 | { count: 10000, value: 1000 },
241 | { count: 1, value: 99942400 }
242 | ]
243 | ```
244 |
245 | -------------------------------------------------------
246 |
247 |
248 | ### histogram.encode()
249 |
250 | Returns a `Buffer` containing a serialized version of the histogram
251 |
252 | -------------------------------------------------------
253 |
254 |
255 | ### histogram.decode(buf)
256 |
257 | Reads a `Buffer` and deserialize an histogram.
258 |
259 | -------------------------------------------------------
260 |
261 |
262 | ### histogram.lowestEquivalentValue(value)
263 |
264 | Get the lowest value that is equivalent to the given value within the
265 | histogram's resolution, where "equivalent" means that value samples
266 | recorded for any two equivalent values are counted in a common total count.
267 |
268 | ------------------------------------------------------
269 |
270 |
271 | ### histogram.highestEquivalentValue(value)
272 |
273 | Get the highest value that is equivalent to the given value within the
274 | histogram's resolution, where "equivalent" means that value samples
275 | recorded for any two equivalent values are counted in a common total count.
276 |
277 | ------------------------------------------------------
278 |
279 |
280 | ### histogram.nextNonEquivalentValue(value)
281 |
282 | Get the next value that is not equivalent to the given value within the histogram's resolution.
283 |
284 | ------------------------------------------------------
285 |
286 |
287 | ### histogram.areValueEquivalent(value1, value2)
288 |
289 | Determine if two values are equivalent within the histogram's resolution
290 | where "equivalent" means that value samples recorded for any two
291 | equivalent values are counted in a common total count.
292 |
293 | -------------------------------------------------------
294 |
295 |
296 | ### histogram.add(other[, expectedIntervalBetweenValueSamples])
297 |
298 | Adds all of the values from `other` to 'this' histogram. Will return the
299 | number of values that are dropped when copying. Values will be dropped
300 | if they around outside of `histogram.lowestTrackableValue` and
301 | `histogram.highestTrackableValue`.
302 |
303 | If `expectedIntervalBetweenValueSamples` is specified, values are
304 | backfilled with values that would have occurred had the client providing the load
305 | not been blocked. The values added will include an auto-generated additional series of
306 | decreasingly-smaller (down to the `expectedIntervalBetweenValueSamples`) value records for each count found
307 | in the current histogram that is larger than the `expectedIntervalBetweenValueSamples`.
308 |
309 | Returns the number of values dropped while copying.
310 |
311 | -------------------------------------------------------
312 |
313 |
314 | ### histogram.reset()
315 |
316 | Resets the histogram so it can be reused.
317 |
318 | -------------------------------------------------------
319 |
320 | ## Properties
321 |
322 |
323 | ### histogram.lowestTrackableValue
324 |
325 | Get the configured lowestTrackableValue
326 |
327 | -------------------------------------------------------
328 |
329 |
330 | ### histogram.highestTrackableValue
331 |
332 | Get the configured highestTrackableValue
333 |
334 | -------------------------------------------------------
335 |
336 | ### histogram.significantFigures
337 |
338 | Get the configured number of significant value digits
339 |
340 | -------------------------------------------------------
341 |
342 | ### histogram.totalCount
343 |
344 | Gets the total number of recorded values.
345 |
346 | -------------------------------------------------------
347 |
348 | ### histogram.memorySize
349 |
350 | Get the memory size of the Histogram.
351 |
352 | -------------------------------------------------------
353 | ## Acknowledgements
354 |
355 | This project was kindly sponsored by [nearForm](http://nearform.com).
356 |
357 | ## License
358 |
359 | This library is licensed as MIT
360 |
361 | HdrHistogram_c is licensed as [BSD license][HdrHistogram_c-license]
362 |
363 | zlib is licensed as [zlib License][zlib-license]
364 |
365 | [hdr]: http://hdrhistogram.org/
366 | [cimpl]: https://github.com/HdrHistogram/HdrHistogram_c
367 | [node-gyp]: https://github.com/nodejs/node-gyp#installation
368 | [mapbox]: http://mapbox.com
369 | [node-pre-gyp]: https://github.com/mapbox/node-pre-gyp
370 | [sqlite3]: https://github.com/mapbox/node-sqlite3
371 | [HdrHistogram_c-license]: https://github.com/HdrHistogram/HdrHistogram_c/blob/master/LICENSE.txt
372 | [sqlite3-scripts-license]: https://github.com/mapbox/node-sqlite3/blob/master/LICENSE
373 | [zlib-license]: http://www.zlib.net/zlib_license.html
374 |
--------------------------------------------------------------------------------
/bench.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const Histogram = require('./')
4 | const max = 1000000
5 | const key = 'record*' + max
6 | const histogram = new Histogram(1, 100)
7 |
8 | console.time(key)
9 | for (let i = 0; i < max; i++) {
10 | histogram.record(Math.floor((Math.random() * 42 + 1)))
11 | }
12 | console.timeEnd(key)
13 |
14 | console.log('80 percentile is', histogram.percentile(80))
15 | console.log('99 percentile is', histogram.percentile(99))
16 |
17 | console.log(histogram.percentiles())
18 |
--------------------------------------------------------------------------------
/binding-src/binding-util/napi-ingress.cc:
--------------------------------------------------------------------------------
1 | // © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
2 | // Released under the MIT License located in the root directory of this repository
3 |
4 | #include "napi-ingress.h"
5 | #include
6 | #include
7 |
8 | void* getVoidPtr (const Napi::Value value) {
9 | return 0;
10 | }
11 |
12 | size_t getStringLength (Napi::Env &env, const Napi::Value value) {
13 | size_t stringLength = 0;
14 | napi_status status = napi_get_value_string_utf8 (env, value, NULL, 0, &stringLength);
15 | if (status != napi_ok) throw "Unable to determine string length.";
16 | return stringLength;
17 | }
18 |
19 | void copyString (Napi::Env &env, const Napi::Value value, char* buffer, size_t bufferLength, size_t stringLength) {
20 | size_t copiedLength = 0;
21 | napi_status status = napi_get_value_string_utf8 (env, value, buffer, bufferLength, &copiedLength);
22 | if (status != napi_ok) throw "String copy failed.";
23 | if (copiedLength != stringLength) throw "String copy length mismatch.";
24 | }
25 |
--------------------------------------------------------------------------------
/binding-src/binding-util/napi-ingress.h:
--------------------------------------------------------------------------------
1 | // © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
2 | // Released under the MIT License located in the root directory of this repository
3 |
4 | #include
5 | using namespace Napi;
6 |
7 | #ifndef _Bool
8 | #define _Bool bool
9 | #endif /* _Bool */
10 |
11 | template inline T getCharacter (Napi::Value value) {
12 | return 'j';
13 | }
14 |
15 | template inline T* getCharacterPtr (Napi::Value value, T& stackAllocated, bool& deletePtr) {
16 | deletePtr = false;
17 | return &stackAllocated;
18 | }
19 |
20 | template inline T getInt32 (Napi::Value value) {
21 | T retVal = static_cast(value.As().Int32Value());
22 | return retVal;
23 | }
24 |
25 | template inline T getUint32 (Napi::Value value) {
26 | T retVal = static_cast(value.As().Uint32Value());
27 | return retVal;
28 | }
29 |
30 | template inline T getInt64 (Napi::Value value) {
31 | T retVal = static_cast(value.As().Int64Value());
32 | return retVal;
33 | }
34 |
35 | template inline T getFloat (Napi::Value value) {
36 | T retVal = static_cast(value.As().FloatValue());
37 | return retVal;
38 | }
39 |
40 | template inline T getDouble (Napi::Value value) {
41 | T retVal = static_cast(value.As().DoubleValue());
42 | return retVal;
43 | }
44 |
45 | template inline T* getNumberPtr (Napi::Value value, T& stackAllocated, bool& deletePtr) {
46 | deletePtr = false;
47 | return &stackAllocated;
48 | }
49 |
50 | void* getVoidPtr (Napi::Value value);
51 |
52 | size_t getStringLength (Napi::Env &env, Napi::Value value);
53 | void copyString (Napi::Env &env, Napi::Value value, char* buffer, size_t bufferLength, size_t stringLength);
--------------------------------------------------------------------------------
/binding-src/binding.cc:
--------------------------------------------------------------------------------
1 | // 2020-07-08T13:10:42.804-07:00 binding (GenerateInitFiles)
2 | // © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
3 | // Released under the MIT License located in the root directory of this repository
4 | // Created by the inspiredware automated binding generator — https://inspiredware.com
5 |
6 | #include
7 | #include "binding/napi-hdr_histogram.h"
8 |
9 | static Napi::FunctionReference ctorHdrHistogram;
10 | static Napi::FunctionReference ctorHdrHistogramIterator;
11 |
12 | Napi::Object Init (Napi::Env env, Napi::Object exports) {
13 | Napi::Function defHdrHistogram = HdrHistogram::GetClassDef(env);
14 | ctorHdrHistogram = Napi::Persistent(defHdrHistogram);
15 | ctorHdrHistogram.SuppressDestruct();
16 |
17 | Napi::Function defHdrHistogramIterator = HdrHistogramIterator::GetClassDef(env);
18 | ctorHdrHistogramIterator = Napi::Persistent(defHdrHistogramIterator);
19 | ctorHdrHistogramIterator.SuppressDestruct();
20 |
21 | exports["HdrHistogram"] = defHdrHistogram;
22 | exports["HdrHistogramIterator"] = defHdrHistogramIterator;
23 |
24 | return exports;
25 | }
26 |
27 | NODE_API_MODULE(addon, Init)
--------------------------------------------------------------------------------
/binding-src/binding/napi-hdr_histogram.h:
--------------------------------------------------------------------------------
1 | // 2020-07-08T13:10:42.125-07:00 binding hdr_histogram.c (GenerateDeclarations)
2 | // © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
3 | // Released under the MIT License located in the root directory of this repository
4 | // Created by the inspiredware automated binding generator — https://inspiredware.com
5 |
6 | #include
7 | #include // from the origin library
8 |
9 | // pseudoClass HdrHistogram declaration begin //
10 |
11 | class HdrHistogram : public Napi::ObjectWrap {
12 | public:
13 | HdrHistogram (const Napi::CallbackInfo& info);
14 | ~HdrHistogram ();
15 | static Napi::Function GetClassDef (Napi::Env env);
16 |
17 | private:
18 | Napi::Value recordCorrectedValue (const Napi::CallbackInfo& info);
19 | Napi::Value recordCorrectedValues (const Napi::CallbackInfo& info);
20 | Napi::Value recordValue (const Napi::CallbackInfo& info);
21 | Napi::Value recordValues (const Napi::CallbackInfo& info);
22 | Napi::Value valuesAreEquivalent (const Napi::CallbackInfo& info);
23 | Napi::Value mean (const Napi::CallbackInfo& info);
24 | Napi::Value stddev (const Napi::CallbackInfo& info);
25 | Napi::Value add (const Napi::CallbackInfo& info);
26 | Napi::Value addWhileCorrectingForCoordinatedOmission (const Napi::CallbackInfo& info);
27 | Napi::Value countAtValue (const Napi::CallbackInfo& info);
28 | Napi::Value lowestEquivalentValue (const Napi::CallbackInfo& info);
29 | Napi::Value max (const Napi::CallbackInfo& info);
30 | Napi::Value medianEquivalentValue (const Napi::CallbackInfo& info);
31 | Napi::Value min (const Napi::CallbackInfo& info);
32 | Napi::Value nextNonEquivalentValue (const Napi::CallbackInfo& info);
33 | Napi::Value percentile (const Napi::CallbackInfo& info);
34 | Napi::Value getMemorySize (const Napi::CallbackInfo& info);
35 | Napi::Value reset (const Napi::CallbackInfo& info);
36 |
37 | Napi::Value getEncoded (const Napi::CallbackInfo& info);
38 | Napi::Value getHighestTrackableValue (const Napi::CallbackInfo& info);
39 | Napi::Value getLowestTrackableValue (const Napi::CallbackInfo& info);
40 | Napi::Value getSignificantFigures (const Napi::CallbackInfo& info);
41 | Napi::Value getTotalCount (const Napi::CallbackInfo& info);
42 | Napi::Value getUnitMagnitude (const Napi::CallbackInfo& info);
43 | Napi::Value setEncoded (const Napi::CallbackInfo& info);
44 |
45 | public:
46 | struct hdr_histogram * histogram;
47 | };
48 | // pseudoClass HdrHistogram declaration end //
49 | // pseudoClass HdrHistogramIterator declaration begin //
50 |
51 | class HdrHistogramIterator : public Napi::ObjectWrap {
52 | public:
53 | HdrHistogramIterator (const Napi::CallbackInfo& info);
54 | ~HdrHistogramIterator ();
55 | static Napi::Function GetClassDef (Napi::Env env);
56 |
57 | private:
58 | Napi::Value next (const Napi::CallbackInfo& info);
59 | Napi::Value initLinear (const Napi::CallbackInfo& info);
60 | Napi::Value initLog (const Napi::CallbackInfo& info);
61 | Napi::Value initPercentile (const Napi::CallbackInfo& info);
62 | Napi::Value initRecorded (const Napi::CallbackInfo& info);
63 |
64 | Napi::Value getValue (const Napi::CallbackInfo& info);
65 | Napi::Value getPercentile (const Napi::CallbackInfo& info);
66 | Napi::Value getCountLinear (const Napi::CallbackInfo& info);
67 | Napi::Value getCountLog (const Napi::CallbackInfo& info);
68 | Napi::Value getCountRecorded (const Napi::CallbackInfo& info);
69 |
70 | struct hdr_iter iterStruct;
71 | struct hdr_iter * iter;
72 | struct hdr_histogram * histogram;
73 | };
74 | // pseudoClass HdrHistogramIterator declaration end //
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | "targets": [
3 | {
4 | "target_name": "histogram",
5 | "sources": [
6 | "binding-src/binding.cc",
7 | "'binding-src/binding-util/'+f).join(' ')\")",
8 | "'binding-src/binding/'+f).join(' ')\")",
9 | "'HdrHistogram_c/src/'+f).join(' ')\")"
10 | ],
11 | "dependencies": [
12 | " typeof value === 'number' && value !== Infinity && value !== -Infinity
6 |
7 | class Histogram extends HdrHistogram {
8 | /**
9 | * Record a value in the histogram.
10 | *
11 | * @param {number} value the value to record.
12 | * @param {number} count the number of times the value is to be recorded (default 1).
13 | * @returns {boolean} true if the recording was successful, false otherwise.
14 | * @memberof Histogram
15 | */
16 | record (value, count) {
17 | if (isNumber(value)) {
18 | if (typeof count === 'undefined') {
19 | return super.recordValue(value)
20 | } else {
21 | return super.recordValues(value, count)
22 | }
23 | } else {
24 | return false
25 | }
26 | }
27 |
28 | /**
29 | * Serialize the histogram.
30 | *
31 | * @returns {Buffer} a Buffer containing a serialized version of the histogram.
32 | * @memberof Histogram
33 | */
34 | encode () {
35 | return super.getEncoded()
36 | }
37 |
38 | /**
39 | * Deserialize a histogram.
40 | *
41 | * @static
42 | * @param {Buffer} encoded a Buffer containing a previously serialized Histogram.
43 | * @returns {Histogram} a new populated Histogram.
44 | * @memberof Histogram
45 | */
46 | static decode (encoded) {
47 | const histogram = new Histogram(1, 10) // the values here are immaterial
48 | histogram.setEncoded(encoded)
49 | return histogram
50 | }
51 |
52 | /**
53 | * Get the value at a given percentile.
54 | *
55 | * @param {number} percentile must be > 0 and <= 100, otherwise it will throw.
56 | * @returns {number} the value at the given percentile.
57 | * @memberof Histogram
58 | */
59 | percentile (percentile) {
60 | if (!isNumber(percentile)) {
61 | throw (Error('No percentile specified'))
62 | } else if (percentile <= 0 || percentile > 100) {
63 | throw (Error('percentile must be > 0 and <= 100'))
64 | } else {
65 | return super.percentile(percentile)
66 | }
67 | }
68 |
69 | /**
70 | * Get all the percentiles.
71 | *
72 | * Used for iterating through histogram values according to percentile levels.
73 | * The iteration is performed in steps that start at 0% and reduce their distance
74 | * to 100% according to the `ticksPerHalfDistance` parameter,
75 | * ultimately reaching 100% when all recorded histogram values are exhausted.
76 | *
77 | * @param {number} ticksPerHalfDistance the number of iteration steps per half-distance to 100% (default 1).
78 | * @returns {Object} an array of objects with `percentile` and `value` numeric properties.
79 | * @memberof Histogram
80 | */
81 | percentiles (ticksPerHalfDistance) {
82 | const result = []
83 | const iter = new HdrHistogramIterator(this)
84 | iter.initPercentile(ticksPerHalfDistance || 1)
85 | while (iter.next()) {
86 | result.push({ percentile: iter.getPercentile(), value: iter.getValue() })
87 | }
88 | return result
89 | }
90 |
91 | /**
92 | * Get the linear counts.
93 | *
94 | * Used for iterating through histogram values in linear steps. The iteration is performed in steps of
95 | * `valueUnitsPerBucket` in size, terminating when all recorded histogram values are exhausted.
96 | *
97 | * Note that each iteration "bucket" includes values up to and including the next bucket boundary value.
98 | *
99 | * @param {number} valueUnitsPerBucket the bucket size as described above.
100 | * @returns {Object} an array of objects with `count` and `value` numeric properties.
101 | * @memberof Histogram
102 | */
103 | linearcounts (valueUnitsPerBucket) {
104 | const result = []
105 | const iter = new HdrHistogramIterator(this)
106 | iter.initLinear(valueUnitsPerBucket)
107 | while (iter.next()) {
108 | result.push({ count: iter.getCountLinear(), value: iter.getValue() })
109 | }
110 | return result
111 | }
112 |
113 | /**
114 | * Get the logarithmic counts.
115 | *
116 | * Used for iterating through histogram values in logarithmically increasing levels.
117 | * The iteration is performed in steps that start at `valueUnitsFirstBucket` and
118 | * increase exponentially according to `logBase`, terminating when all recorded histogram
119 | * values are exhausted.
120 | *
121 | * Note that each iteration "bucket" includes values up to and including the next bucket boundary value.
122 | *
123 | * @param {number} valueUnitsFirstBucket the value units for the first bucket as described above.
124 | * @param {number} logBase the logarithmic base as described above.
125 | * @returns {Object} an array of objects with `count` and `value` numeric properties.
126 | * @memberof Histogram
127 | */
128 | logcounts (valueUnitsFirstBucket, logBase) {
129 | const result = []
130 | const iter = new HdrHistogramIterator(this)
131 | iter.initLog(valueUnitsFirstBucket, logBase)
132 | while (iter.next()) {
133 | result.push({ count: iter.getCountLog(), value: iter.getValue() })
134 | }
135 | return result
136 | }
137 |
138 | /**
139 | * Get the recorded counts.
140 | *
141 | * Used for iterating through all recorded histogram values using the finest granularity
142 | * steps supported by the underlying representation. The iteration steps through all non-zero
143 | * recorded value counts, and terminates when all recorded histogram values are exhausted.
144 | *
145 | * @returns {Object} an array of objects with `count` and `value` numeric properties.
146 | * @memberof Histogram
147 | */
148 | recordedcounts () {
149 | const result = []
150 | const iter = new HdrHistogramIterator(this)
151 | iter.initRecorded()
152 | while (iter.next()) {
153 | result.push({ count: iter.getCountRecorded(), value: iter.getValue() })
154 | }
155 | return result
156 | }
157 |
158 | /**
159 | * Reset the Histogram so it can be reused.
160 | *
161 | * @returns {Histogram} the empty Histogram.
162 | * @memberof Histogram
163 | */
164 | reset () {
165 | super.reset()
166 | return this
167 | }
168 |
169 | /**
170 | * Add values from another Histogram.
171 | *
172 | * @param {Histogram} histogram the Histogram containing the values to be added.
173 | * @param {number} expectedInterval the delay between recording values (optional).
174 | * @returns {number} the number of dropped values.
175 | * @memberof Histogram
176 | */
177 | add (histogram, expectedInterval) {
178 | if (typeof expectedInterval === 'undefined') {
179 | return super.add(histogram)
180 | } else {
181 | return super.addWhileCorrectingForCoordinatedOmission(histogram, expectedInterval)
182 | }
183 | }
184 |
185 | /**
186 | * Get the highest value that is equivalent to the given value within the histogram's resolution.
187 | *
188 | * @param {number} value the value for which the highest equivalent value is to be determined.
189 | * @returns {number} the highest equivalent value.
190 | * @memberof Histogram
191 | */
192 | highestEquivalentValue (value) {
193 | return super.nextNonEquivalentValue(value) - 1
194 | }
195 | }
196 |
197 | module.exports = Histogram
198 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "native-hdr-histogram",
3 | "version": "1.0.0",
4 | "description": "node.js bindings for hdr histogram C implementation",
5 | "main": "histogram.js",
6 | "gypfile": "true",
7 | "scripts": {
8 | "install": "node-gyp-build",
9 | "prebuild": "prebuildify --napi",
10 | "test": "standard && tap test.js"
11 | },
12 | "precommit": [
13 | "test"
14 | ],
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/mcollina/native-hdr-histogram.git"
18 | },
19 | "keywords": [
20 | "hdr",
21 | "histogram",
22 | "native",
23 | "n-api"
24 | ],
25 | "author": "Matteo Collina ",
26 | "contributors": [
27 | "Glen Keane (http://glenkeane.me/)",
28 | "Jim Schlight (https://github.com/jschlight)"
29 | ],
30 | "license": "MIT",
31 | "bugs": {
32 | "url": "https://github.com/mcollina/native-hdr-histogram/issues"
33 | },
34 | "homepage": "https://github.com/mcollina/native-hdr-histogram#readme",
35 | "devDependencies": {
36 | "pre-commit": "^1.2.2",
37 | "prebuildify": "^4.0.0",
38 | "prebuildify-ci": "^1.0.5",
39 | "standard": "^14.3.4",
40 | "tap": "^14.0.0"
41 | },
42 | "dependencies": {
43 | "node-addon-api": "^3.0.0",
44 | "node-gyp-build": "^4.2.3"
45 | },
46 | "files": [
47 | "binding-src/",
48 | "HdrHistogram_c/src/",
49 | "prebuilds/",
50 | "zlib/",
51 | "binding.gyp",
52 | "histogram.js",
53 | "package.json",
54 | "LICENSE",
55 | "README.md"
56 | ]
57 | }
58 |
--------------------------------------------------------------------------------
/scripts/README.md:
--------------------------------------------------------------------------------
1 | ## About these scripts
2 |
3 | ### Publishing
4 |
5 | Two scripts are provided for publishing the native addon as an npm module.
6 |
7 | #### publish-local.sh
8 |
9 | This script publishes the current working directory to the npm registry.
10 |
11 | This script is quick and easy to run, but relies on the user to verify that the contents of the current working directory accurately reflect those of the repository's `master` branch.
12 |
13 | #### publish-github.sh
14 |
15 | This script sends a `POST` request to the GitHub API that triggers the `publish.yml` workflow on the `master` branch. Although more involved than the `publish-local.sh` script, this script insures that the contents of the npm module exactly match those of the repository's `master` branch. But perhaps the biggest advantage of this approach is that it creates a permanent and verifiable record of the publishing process on the project's GitHub repository.
16 |
17 | This script has the following requirements:
18 |
19 | - The `GITHUB_TOKEN` environment variable on the local machine running the script must contain a GitHub personal access token with `repo` permission for the GitHub repository.
20 |
21 | - The settings of the GitHub repository where the workflow is running must include an `NPM_TOKEN` GitHub secret containing a valid npm authentication token for the npm registry.
22 |
23 | - The token specified in the `NPM_TOKEN` GitHub secret must have the **Publish** capability.
24 |
25 | - If Two-Factor Authentication is enabled for the npm account where the module is being published, the "2FA Mode" must be for **Authorization** only and not for **Authorization and Publishing**.
26 |
--------------------------------------------------------------------------------
/scripts/publish-github.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | curl -H "Accept: application/vnd.github.everest-preview+json" \
3 | -H "Authorization: token ${GITHUB_TOKEN}" \
4 | --request POST \
5 | --data '{"ref": "master"}' \
6 | https://api.github.com/repos/mcollina/native-hdr-histogram/actions/workflows/publish.yml/dispatches
7 |
--------------------------------------------------------------------------------
/scripts/publish-local.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | npm install
3 | npx prebuildify-ci download
4 | npm publish
--------------------------------------------------------------------------------
/zlib/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.4.4)
2 | set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3 |
4 | project(zlib C)
5 |
6 | set(VERSION "1.2.11")
7 |
8 | option(ASM686 "Enable building i686 assembly implementation")
9 | option(AMD64 "Enable building amd64 assembly implementation")
10 |
11 | set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
12 | set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
13 | set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
14 | set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
15 | set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
16 |
17 | include(CheckTypeSize)
18 | include(CheckFunctionExists)
19 | include(CheckIncludeFile)
20 | include(CheckCSourceCompiles)
21 | enable_testing()
22 |
23 | check_include_file(sys/types.h HAVE_SYS_TYPES_H)
24 | check_include_file(stdint.h HAVE_STDINT_H)
25 | check_include_file(stddef.h HAVE_STDDEF_H)
26 |
27 | #
28 | # Check to see if we have large file support
29 | #
30 | set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
31 | # We add these other definitions here because CheckTypeSize.cmake
32 | # in CMake 2.4.x does not automatically do so and we want
33 | # compatibility with CMake 2.4.x.
34 | if(HAVE_SYS_TYPES_H)
35 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
36 | endif()
37 | if(HAVE_STDINT_H)
38 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
39 | endif()
40 | if(HAVE_STDDEF_H)
41 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
42 | endif()
43 | check_type_size(off64_t OFF64_T)
44 | if(HAVE_OFF64_T)
45 | add_definitions(-D_LARGEFILE64_SOURCE=1)
46 | endif()
47 | set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
48 |
49 | #
50 | # Check for fseeko
51 | #
52 | check_function_exists(fseeko HAVE_FSEEKO)
53 | if(NOT HAVE_FSEEKO)
54 | add_definitions(-DNO_FSEEKO)
55 | endif()
56 |
57 | #
58 | # Check for unistd.h
59 | #
60 | check_include_file(unistd.h Z_HAVE_UNISTD_H)
61 |
62 | if(MSVC)
63 | set(CMAKE_DEBUG_POSTFIX "d")
64 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
65 | add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
66 | include_directories(${CMAKE_CURRENT_SOURCE_DIR})
67 | endif()
68 |
69 | if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
70 | # If we're doing an out of source build and the user has a zconf.h
71 | # in their source tree...
72 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
73 | message(STATUS "Renaming")
74 | message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
75 | message(STATUS "to 'zconf.h.included' because this file is included with zlib")
76 | message(STATUS "but CMake generates it automatically in the build directory.")
77 | file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
78 | endif()
79 | endif()
80 |
81 | set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
82 | configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
83 | ${ZLIB_PC} @ONLY)
84 | configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
85 | ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
86 | include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
87 |
88 |
89 | #============================================================================
90 | # zlib
91 | #============================================================================
92 |
93 | set(ZLIB_PUBLIC_HDRS
94 | ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
95 | zlib.h
96 | )
97 | set(ZLIB_PRIVATE_HDRS
98 | crc32.h
99 | deflate.h
100 | gzguts.h
101 | inffast.h
102 | inffixed.h
103 | inflate.h
104 | inftrees.h
105 | trees.h
106 | zutil.h
107 | )
108 | set(ZLIB_SRCS
109 | adler32.c
110 | compress.c
111 | crc32.c
112 | deflate.c
113 | gzclose.c
114 | gzlib.c
115 | gzread.c
116 | gzwrite.c
117 | inflate.c
118 | infback.c
119 | inftrees.c
120 | inffast.c
121 | trees.c
122 | uncompr.c
123 | zutil.c
124 | )
125 |
126 | if(NOT MINGW)
127 | set(ZLIB_DLL_SRCS
128 | win32/zlib1.rc # If present will override custom build rule below.
129 | )
130 | endif()
131 |
132 | if(CMAKE_COMPILER_IS_GNUCC)
133 | if(ASM686)
134 | set(ZLIB_ASMS contrib/asm686/match.S)
135 | elseif (AMD64)
136 | set(ZLIB_ASMS contrib/amd64/amd64-match.S)
137 | endif ()
138 |
139 | if(ZLIB_ASMS)
140 | add_definitions(-DASMV)
141 | set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
142 | endif()
143 | endif()
144 |
145 | if(MSVC)
146 | if(ASM686)
147 | ENABLE_LANGUAGE(ASM_MASM)
148 | set(ZLIB_ASMS
149 | contrib/masmx86/inffas32.asm
150 | contrib/masmx86/match686.asm
151 | )
152 | elseif (AMD64)
153 | ENABLE_LANGUAGE(ASM_MASM)
154 | set(ZLIB_ASMS
155 | contrib/masmx64/gvmat64.asm
156 | contrib/masmx64/inffasx64.asm
157 | )
158 | endif()
159 |
160 | if(ZLIB_ASMS)
161 | add_definitions(-DASMV -DASMINF)
162 | endif()
163 | endif()
164 |
165 | # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
166 | file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
167 | string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
168 | "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
169 |
170 | if(MINGW)
171 | # This gets us DLL resource information when compiling on MinGW.
172 | if(NOT CMAKE_RC_COMPILER)
173 | set(CMAKE_RC_COMPILER windres.exe)
174 | endif()
175 |
176 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
177 | COMMAND ${CMAKE_RC_COMPILER}
178 | -D GCC_WINDRES
179 | -I ${CMAKE_CURRENT_SOURCE_DIR}
180 | -I ${CMAKE_CURRENT_BINARY_DIR}
181 | -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
182 | -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
183 | set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
184 | endif(MINGW)
185 |
186 | add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
187 | add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
188 | set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
189 | set_target_properties(zlib PROPERTIES SOVERSION 1)
190 |
191 | if(NOT CYGWIN)
192 | # This property causes shared libraries on Linux to have the full version
193 | # encoded into their final filename. We disable this on Cygwin because
194 | # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
195 | # seems to be the default.
196 | #
197 | # This has no effect with MSVC, on that platform the version info for
198 | # the DLL comes from the resource file win32/zlib1.rc
199 | set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
200 | endif()
201 |
202 | if(UNIX)
203 | # On unix-like platforms the library is almost always called libz
204 | set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
205 | if(NOT APPLE)
206 | set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
207 | endif()
208 | elseif(BUILD_SHARED_LIBS AND WIN32)
209 | # Creates zlib1.dll when building shared library version
210 | set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
211 | endif()
212 |
213 | if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
214 | install(TARGETS zlib zlibstatic
215 | RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
216 | ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
217 | LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
218 | endif()
219 | if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
220 | install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
221 | endif()
222 | if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
223 | install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
224 | endif()
225 | if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
226 | install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
227 | endif()
228 |
229 | #============================================================================
230 | # Example binaries
231 | #============================================================================
232 |
233 | add_executable(example test/example.c)
234 | target_link_libraries(example zlib)
235 | add_test(example example)
236 |
237 | add_executable(minigzip test/minigzip.c)
238 | target_link_libraries(minigzip zlib)
239 |
240 | if(HAVE_OFF64_T)
241 | add_executable(example64 test/example.c)
242 | target_link_libraries(example64 zlib)
243 | set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
244 | add_test(example64 example64)
245 |
246 | add_executable(minigzip64 test/minigzip.c)
247 | target_link_libraries(minigzip64 zlib)
248 | set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
249 | endif()
250 |
--------------------------------------------------------------------------------
/zlib/INDEX:
--------------------------------------------------------------------------------
1 | CMakeLists.txt cmake build file
2 | ChangeLog history of changes
3 | FAQ Frequently Asked Questions about zlib
4 | INDEX this file
5 | Makefile dummy Makefile that tells you to ./configure
6 | Makefile.in template for Unix Makefile
7 | README guess what
8 | configure configure script for Unix
9 | make_vms.com makefile for VMS
10 | test/example.c zlib usages examples for build testing
11 | test/minigzip.c minimal gzip-like functionality for build testing
12 | test/infcover.c inf*.c code coverage for build coverage testing
13 | treebuild.xml XML description of source file dependencies
14 | zconf.h.cmakein zconf.h template for cmake
15 | zconf.h.in zconf.h template for configure
16 | zlib.3 Man page for zlib
17 | zlib.3.pdf Man page in PDF format
18 | zlib.map Linux symbol information
19 | zlib.pc.in Template for pkg-config descriptor
20 | zlib.pc.cmakein zlib.pc template for cmake
21 | zlib2ansi perl script to convert source files for C++ compilation
22 |
23 | amiga/ makefiles for Amiga SAS C
24 | as400/ makefiles for AS/400
25 | doc/ documentation for formats and algorithms
26 | msdos/ makefiles for MSDOS
27 | nintendods/ makefile for Nintendo DS
28 | old/ makefiles for various architectures and zlib documentation
29 | files that have not yet been updated for zlib 1.2.x
30 | qnx/ makefiles for QNX
31 | watcom/ makefiles for OpenWatcom
32 | win32/ makefiles for Windows
33 |
34 | zlib public header files (required for library use):
35 | zconf.h
36 | zlib.h
37 |
38 | private source files used to build the zlib library:
39 | adler32.c
40 | compress.c
41 | crc32.c
42 | crc32.h
43 | deflate.c
44 | deflate.h
45 | gzclose.c
46 | gzguts.h
47 | gzlib.c
48 | gzread.c
49 | gzwrite.c
50 | infback.c
51 | inffast.c
52 | inffast.h
53 | inffixed.h
54 | inflate.c
55 | inflate.h
56 | inftrees.c
57 | inftrees.h
58 | trees.c
59 | trees.h
60 | uncompr.c
61 | zutil.c
62 | zutil.h
63 |
64 | source files for sample programs
65 | See examples/README.examples
66 |
67 | unsupported contributions by third parties
68 | See contrib/README.contrib
69 |
--------------------------------------------------------------------------------
/zlib/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | -@echo "Please use ./configure first. Thank you."
3 |
4 | distclean:
5 | make -f Makefile.in distclean
6 |
--------------------------------------------------------------------------------
/zlib/Makefile.in:
--------------------------------------------------------------------------------
1 | # Makefile for zlib
2 | # Copyright (C) 1995-2017 Jean-loup Gailly, Mark Adler
3 | # For conditions of distribution and use, see copyright notice in zlib.h
4 |
5 | # To compile and test, type:
6 | # ./configure; make test
7 | # Normally configure builds both a static and a shared library.
8 | # If you want to build just a static library, use: ./configure --static
9 |
10 | # To use the asm code, type:
11 | # cp contrib/asm?86/match.S ./match.S
12 | # make LOC=-DASMV OBJA=match.o
13 |
14 | # To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
15 | # make install
16 | # To install in $HOME instead of /usr/local, use:
17 | # make install prefix=$HOME
18 |
19 | CC=cc
20 |
21 | CFLAGS=-O
22 | #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
23 | #CFLAGS=-g -DZLIB_DEBUG
24 | #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
25 | # -Wstrict-prototypes -Wmissing-prototypes
26 |
27 | SFLAGS=-O
28 | LDFLAGS=
29 | TEST_LDFLAGS=-L. libz.a
30 | LDSHARED=$(CC)
31 | CPP=$(CC) -E
32 |
33 | STATICLIB=libz.a
34 | SHAREDLIB=libz.so
35 | SHAREDLIBV=libz.so.1.2.11
36 | SHAREDLIBM=libz.so.1
37 | LIBS=$(STATICLIB) $(SHAREDLIBV)
38 |
39 | AR=ar
40 | ARFLAGS=rc
41 | RANLIB=ranlib
42 | LDCONFIG=ldconfig
43 | LDSHAREDLIBC=-lc
44 | TAR=tar
45 | SHELL=/bin/sh
46 | EXE=
47 |
48 | prefix = /usr/local
49 | exec_prefix = ${prefix}
50 | libdir = ${exec_prefix}/lib
51 | sharedlibdir = ${libdir}
52 | includedir = ${prefix}/include
53 | mandir = ${prefix}/share/man
54 | man3dir = ${mandir}/man3
55 | pkgconfigdir = ${libdir}/pkgconfig
56 | SRCDIR=
57 | ZINC=
58 | ZINCOUT=-I.
59 |
60 | OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
61 | OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
62 | OBJC = $(OBJZ) $(OBJG)
63 |
64 | PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo
65 | PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo
66 | PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
67 |
68 | # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
69 | OBJA =
70 | PIC_OBJA =
71 |
72 | OBJS = $(OBJC) $(OBJA)
73 |
74 | PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
75 |
76 | all: static shared
77 |
78 | static: example$(EXE) minigzip$(EXE)
79 |
80 | shared: examplesh$(EXE) minigzipsh$(EXE)
81 |
82 | all64: example64$(EXE) minigzip64$(EXE)
83 |
84 | check: test
85 |
86 | test: all teststatic testshared
87 |
88 | teststatic: static
89 | @TMPST=tmpst_$$; \
90 | if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \
91 | echo ' *** zlib test OK ***'; \
92 | else \
93 | echo ' *** zlib test FAILED ***'; false; \
94 | fi; \
95 | rm -f $$TMPST
96 |
97 | testshared: shared
98 | @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
99 | LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
100 | DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
101 | SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
102 | TMPSH=tmpsh_$$; \
103 | if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \
104 | echo ' *** zlib shared test OK ***'; \
105 | else \
106 | echo ' *** zlib shared test FAILED ***'; false; \
107 | fi; \
108 | rm -f $$TMPSH
109 |
110 | test64: all64
111 | @TMP64=tmp64_$$; \
112 | if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \
113 | echo ' *** zlib 64-bit test OK ***'; \
114 | else \
115 | echo ' *** zlib 64-bit test FAILED ***'; false; \
116 | fi; \
117 | rm -f $$TMP64
118 |
119 | infcover.o: $(SRCDIR)test/infcover.c $(SRCDIR)zlib.h zconf.h
120 | $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/infcover.c
121 |
122 | infcover: infcover.o libz.a
123 | $(CC) $(CFLAGS) -o $@ infcover.o libz.a
124 |
125 | cover: infcover
126 | rm -f *.gcda
127 | ./infcover
128 | gcov inf*.c
129 |
130 | libz.a: $(OBJS)
131 | $(AR) $(ARFLAGS) $@ $(OBJS)
132 | -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
133 |
134 | match.o: match.S
135 | $(CPP) match.S > _match.s
136 | $(CC) -c _match.s
137 | mv _match.o match.o
138 | rm -f _match.s
139 |
140 | match.lo: match.S
141 | $(CPP) match.S > _match.s
142 | $(CC) -c -fPIC _match.s
143 | mv _match.o match.lo
144 | rm -f _match.s
145 |
146 | example.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
147 | $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/example.c
148 |
149 | minigzip.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
150 | $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/minigzip.c
151 |
152 | example64.o: $(SRCDIR)test/example.c $(SRCDIR)zlib.h zconf.h
153 | $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/example.c
154 |
155 | minigzip64.o: $(SRCDIR)test/minigzip.c $(SRCDIR)zlib.h zconf.h
156 | $(CC) $(CFLAGS) $(ZINCOUT) -D_FILE_OFFSET_BITS=64 -c -o $@ $(SRCDIR)test/minigzip.c
157 |
158 |
159 | adler32.o: $(SRCDIR)adler32.c
160 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)adler32.c
161 |
162 | crc32.o: $(SRCDIR)crc32.c
163 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)crc32.c
164 |
165 | deflate.o: $(SRCDIR)deflate.c
166 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)deflate.c
167 |
168 | infback.o: $(SRCDIR)infback.c
169 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)infback.c
170 |
171 | inffast.o: $(SRCDIR)inffast.c
172 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inffast.c
173 |
174 | inflate.o: $(SRCDIR)inflate.c
175 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inflate.c
176 |
177 | inftrees.o: $(SRCDIR)inftrees.c
178 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)inftrees.c
179 |
180 | trees.o: $(SRCDIR)trees.c
181 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)trees.c
182 |
183 | zutil.o: $(SRCDIR)zutil.c
184 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)zutil.c
185 |
186 | compress.o: $(SRCDIR)compress.c
187 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)compress.c
188 |
189 | uncompr.o: $(SRCDIR)uncompr.c
190 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)uncompr.c
191 |
192 | gzclose.o: $(SRCDIR)gzclose.c
193 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzclose.c
194 |
195 | gzlib.o: $(SRCDIR)gzlib.c
196 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzlib.c
197 |
198 | gzread.o: $(SRCDIR)gzread.c
199 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzread.c
200 |
201 | gzwrite.o: $(SRCDIR)gzwrite.c
202 | $(CC) $(CFLAGS) $(ZINC) -c -o $@ $(SRCDIR)gzwrite.c
203 |
204 |
205 | adler32.lo: $(SRCDIR)adler32.c
206 | -@mkdir objs 2>/dev/null || test -d objs
207 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/adler32.o $(SRCDIR)adler32.c
208 | -@mv objs/adler32.o $@
209 |
210 | crc32.lo: $(SRCDIR)crc32.c
211 | -@mkdir objs 2>/dev/null || test -d objs
212 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/crc32.o $(SRCDIR)crc32.c
213 | -@mv objs/crc32.o $@
214 |
215 | deflate.lo: $(SRCDIR)deflate.c
216 | -@mkdir objs 2>/dev/null || test -d objs
217 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/deflate.o $(SRCDIR)deflate.c
218 | -@mv objs/deflate.o $@
219 |
220 | infback.lo: $(SRCDIR)infback.c
221 | -@mkdir objs 2>/dev/null || test -d objs
222 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/infback.o $(SRCDIR)infback.c
223 | -@mv objs/infback.o $@
224 |
225 | inffast.lo: $(SRCDIR)inffast.c
226 | -@mkdir objs 2>/dev/null || test -d objs
227 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inffast.o $(SRCDIR)inffast.c
228 | -@mv objs/inffast.o $@
229 |
230 | inflate.lo: $(SRCDIR)inflate.c
231 | -@mkdir objs 2>/dev/null || test -d objs
232 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inflate.o $(SRCDIR)inflate.c
233 | -@mv objs/inflate.o $@
234 |
235 | inftrees.lo: $(SRCDIR)inftrees.c
236 | -@mkdir objs 2>/dev/null || test -d objs
237 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/inftrees.o $(SRCDIR)inftrees.c
238 | -@mv objs/inftrees.o $@
239 |
240 | trees.lo: $(SRCDIR)trees.c
241 | -@mkdir objs 2>/dev/null || test -d objs
242 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/trees.o $(SRCDIR)trees.c
243 | -@mv objs/trees.o $@
244 |
245 | zutil.lo: $(SRCDIR)zutil.c
246 | -@mkdir objs 2>/dev/null || test -d objs
247 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/zutil.o $(SRCDIR)zutil.c
248 | -@mv objs/zutil.o $@
249 |
250 | compress.lo: $(SRCDIR)compress.c
251 | -@mkdir objs 2>/dev/null || test -d objs
252 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/compress.o $(SRCDIR)compress.c
253 | -@mv objs/compress.o $@
254 |
255 | uncompr.lo: $(SRCDIR)uncompr.c
256 | -@mkdir objs 2>/dev/null || test -d objs
257 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/uncompr.o $(SRCDIR)uncompr.c
258 | -@mv objs/uncompr.o $@
259 |
260 | gzclose.lo: $(SRCDIR)gzclose.c
261 | -@mkdir objs 2>/dev/null || test -d objs
262 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzclose.o $(SRCDIR)gzclose.c
263 | -@mv objs/gzclose.o $@
264 |
265 | gzlib.lo: $(SRCDIR)gzlib.c
266 | -@mkdir objs 2>/dev/null || test -d objs
267 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzlib.o $(SRCDIR)gzlib.c
268 | -@mv objs/gzlib.o $@
269 |
270 | gzread.lo: $(SRCDIR)gzread.c
271 | -@mkdir objs 2>/dev/null || test -d objs
272 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzread.o $(SRCDIR)gzread.c
273 | -@mv objs/gzread.o $@
274 |
275 | gzwrite.lo: $(SRCDIR)gzwrite.c
276 | -@mkdir objs 2>/dev/null || test -d objs
277 | $(CC) $(SFLAGS) $(ZINC) -DPIC -c -o objs/gzwrite.o $(SRCDIR)gzwrite.c
278 | -@mv objs/gzwrite.o $@
279 |
280 |
281 | placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a
282 | $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
283 | rm -f $(SHAREDLIB) $(SHAREDLIBM)
284 | ln -s $@ $(SHAREDLIB)
285 | ln -s $@ $(SHAREDLIBM)
286 | -@rmdir objs
287 |
288 | example$(EXE): example.o $(STATICLIB)
289 | $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
290 |
291 | minigzip$(EXE): minigzip.o $(STATICLIB)
292 | $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
293 |
294 | examplesh$(EXE): example.o $(SHAREDLIBV)
295 | $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
296 |
297 | minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
298 | $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
299 |
300 | example64$(EXE): example64.o $(STATICLIB)
301 | $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
302 |
303 | minigzip64$(EXE): minigzip64.o $(STATICLIB)
304 | $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
305 |
306 | install-libs: $(LIBS)
307 | -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
308 | -@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
309 | -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
310 | -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
311 | -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
312 | rm -f $(DESTDIR)$(libdir)/$(STATICLIB)
313 | cp $(STATICLIB) $(DESTDIR)$(libdir)
314 | chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB)
315 | -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1
316 | -@if test -n "$(SHAREDLIBV)"; then \
317 | rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
318 | cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \
319 | echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \
320 | chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \
321 | echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \
322 | rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
323 | ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \
324 | ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \
325 | ($(LDCONFIG) || true) >/dev/null 2>&1; \
326 | fi
327 | rm -f $(DESTDIR)$(man3dir)/zlib.3
328 | cp $(SRCDIR)zlib.3 $(DESTDIR)$(man3dir)
329 | chmod 644 $(DESTDIR)$(man3dir)/zlib.3
330 | rm -f $(DESTDIR)$(pkgconfigdir)/zlib.pc
331 | cp zlib.pc $(DESTDIR)$(pkgconfigdir)
332 | chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
333 | # The ranlib in install is needed on NeXTSTEP which checks file times
334 | # ldconfig is for Linux
335 |
336 | install: install-libs
337 | -@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
338 | rm -f $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
339 | cp $(SRCDIR)zlib.h zconf.h $(DESTDIR)$(includedir)
340 | chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
341 |
342 | uninstall:
343 | cd $(DESTDIR)$(includedir) && rm -f zlib.h zconf.h
344 | cd $(DESTDIR)$(libdir) && rm -f libz.a; \
345 | if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
346 | rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
347 | fi
348 | cd $(DESTDIR)$(man3dir) && rm -f zlib.3
349 | cd $(DESTDIR)$(pkgconfigdir) && rm -f zlib.pc
350 |
351 | docs: zlib.3.pdf
352 |
353 | zlib.3.pdf: $(SRCDIR)zlib.3
354 | groff -mandoc -f H -T ps $(SRCDIR)zlib.3 | ps2pdf - $@
355 |
356 | zconf.h.cmakein: $(SRCDIR)zconf.h.in
357 | -@ TEMPFILE=zconfh_$$; \
358 | echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\
359 | sed -f $$TEMPFILE $(SRCDIR)zconf.h.in > $@ &&\
360 | touch -r $(SRCDIR)zconf.h.in $@ &&\
361 | rm $$TEMPFILE
362 |
363 | zconf: $(SRCDIR)zconf.h.in
364 | cp -p $(SRCDIR)zconf.h.in zconf.h
365 |
366 | mostlyclean: clean
367 | clean:
368 | rm -f *.o *.lo *~ \
369 | example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
370 | example64$(EXE) minigzip64$(EXE) \
371 | infcover \
372 | libz.* foo.gz so_locations \
373 | _match.s maketree contrib/infback9/*.o
374 | rm -rf objs
375 | rm -f *.gcda *.gcno *.gcov
376 | rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov
377 |
378 | maintainer-clean: distclean
379 | distclean: clean zconf zconf.h.cmakein docs
380 | rm -f Makefile zlib.pc configure.log
381 | -@rm -f .DS_Store
382 | @if [ -f Makefile.in ]; then \
383 | printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile ; \
384 | printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile ; \
385 | touch -r $(SRCDIR)Makefile.in Makefile ; fi
386 | @if [ ! -f zconf.h.in ]; then rm -f zconf.h zconf.h.cmakein ; fi
387 | @if [ ! -f zlib.3 ]; then rm -f zlib.3.pdf ; fi
388 |
389 | tags:
390 | etags $(SRCDIR)*.[ch]
391 |
392 | adler32.o zutil.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
393 | gzclose.o gzlib.o gzread.o gzwrite.o: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
394 | compress.o example.o minigzip.o uncompr.o: $(SRCDIR)zlib.h zconf.h
395 | crc32.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
396 | deflate.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
397 | infback.o inflate.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
398 | inffast.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
399 | inftrees.o: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
400 | trees.o: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
401 |
402 | adler32.lo zutil.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
403 | gzclose.lo gzlib.lo gzread.lo gzwrite.lo: $(SRCDIR)zlib.h zconf.h $(SRCDIR)gzguts.h
404 | compress.lo example.lo minigzip.lo uncompr.lo: $(SRCDIR)zlib.h zconf.h
405 | crc32.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)crc32.h
406 | deflate.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h
407 | infback.lo inflate.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h $(SRCDIR)inffixed.h
408 | inffast.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h $(SRCDIR)inflate.h $(SRCDIR)inffast.h
409 | inftrees.lo: $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)inftrees.h
410 | trees.lo: $(SRCDIR)deflate.h $(SRCDIR)zutil.h $(SRCDIR)zlib.h zconf.h $(SRCDIR)trees.h
411 |
--------------------------------------------------------------------------------
/zlib/README:
--------------------------------------------------------------------------------
1 | ZLIB DATA COMPRESSION LIBRARY
2 |
3 | zlib 1.2.11 is a general purpose data compression library. All the code is
4 | thread safe. The data format used by the zlib library is described by RFCs
5 | (Request for Comments) 1950 to 1952 in the files
6 | http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
7 | rfc1952 (gzip format).
8 |
9 | All functions of the compression library are documented in the file zlib.h
10 | (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
11 | of the library is given in the file test/example.c which also tests that
12 | the library is working correctly. Another example is given in the file
13 | test/minigzip.c. The compression library itself is composed of all source
14 | files in the root directory.
15 |
16 | To compile all files and run the test program, follow the instructions given at
17 | the top of Makefile.in. In short "./configure; make test", and if that goes
18 | well, "make install" should work for most flavors of Unix. For Windows, use
19 | one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
20 | make_vms.com.
21 |
22 | Questions about zlib should be sent to , or to Gilles Vollant
23 | for the Windows DLL version. The zlib home page is
24 | http://zlib.net/ . Before reporting a problem, please check this site to
25 | verify that you have the latest version of zlib; otherwise get the latest
26 | version and check whether the problem still exists or not.
27 |
28 | PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
29 |
30 | Mark Nelson wrote an article about zlib for the Jan. 1997
31 | issue of Dr. Dobb's Journal; a copy of the article is available at
32 | http://marknelson.us/1997/01/01/zlib-engine/ .
33 |
34 | The changes made in version 1.2.11 are documented in the file ChangeLog.
35 |
36 | Unsupported third party contributions are provided in directory contrib/ .
37 |
38 | zlib is available in Java using the java.util.zip package, documented at
39 | http://java.sun.com/developer/technicalArticles/Programming/compression/ .
40 |
41 | A Perl interface to zlib written by Paul Marquess is available
42 | at CPAN (Comprehensive Perl Archive Network) sites, including
43 | http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
44 |
45 | A Python interface to zlib written by A.M. Kuchling is
46 | available in Python 1.5 and later versions, see
47 | http://docs.python.org/library/zlib.html .
48 |
49 | zlib is built into tcl: http://wiki.tcl.tk/4610 .
50 |
51 | An experimental package to read and write files in .zip format, written on top
52 | of zlib by Gilles Vollant , is available in the
53 | contrib/minizip directory of zlib.
54 |
55 |
56 | Notes for some targets:
57 |
58 | - For Windows DLL versions, please see win32/DLL_FAQ.txt
59 |
60 | - For 64-bit Irix, deflate.c must be compiled without any optimization. With
61 | -O, one libpng test fails. The test works in 32 bit mode (with the -n32
62 | compiler flag). The compiler bug has been reported to SGI.
63 |
64 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
65 | when compiled with cc.
66 |
67 | - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
68 | necessary to get gzprintf working correctly. This is done by configure.
69 |
70 | - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
71 | other compilers. Use "make test" to check your compiler.
72 |
73 | - gzdopen is not supported on RISCOS or BEOS.
74 |
75 | - For PalmOs, see http://palmzlib.sourceforge.net/
76 |
77 |
78 | Acknowledgments:
79 |
80 | The deflate format used by zlib was defined by Phil Katz. The deflate and
81 | zlib specifications were written by L. Peter Deutsch. Thanks to all the
82 | people who reported problems and suggested various improvements in zlib; they
83 | are too numerous to cite here.
84 |
85 | Copyright notice:
86 |
87 | (C) 1995-2017 Jean-loup Gailly and Mark Adler
88 |
89 | This software is provided 'as-is', without any express or implied
90 | warranty. In no event will the authors be held liable for any damages
91 | arising from the use of this software.
92 |
93 | Permission is granted to anyone to use this software for any purpose,
94 | including commercial applications, and to alter it and redistribute it
95 | freely, subject to the following restrictions:
96 |
97 | 1. The origin of this software must not be misrepresented; you must not
98 | claim that you wrote the original software. If you use this software
99 | in a product, an acknowledgment in the product documentation would be
100 | appreciated but is not required.
101 | 2. Altered source versions must be plainly marked as such, and must not be
102 | misrepresented as being the original software.
103 | 3. This notice may not be removed or altered from any source distribution.
104 |
105 | Jean-loup Gailly Mark Adler
106 | jloup@gzip.org madler@alumni.caltech.edu
107 |
108 | If you use the zlib library in a product, we would appreciate *not* receiving
109 | lengthy legal documents to sign. The sources are provided for free but without
110 | warranty of any kind. The library has been entirely written by Jean-loup
111 | Gailly and Mark Adler; it does not include third-party code.
112 |
113 | If you redistribute modified sources, we would appreciate that you include in
114 | the file ChangeLog history information documenting your changes. Please read
115 | the FAQ for more information on the distribution of modified source versions.
116 |
--------------------------------------------------------------------------------
/zlib/adler32.c:
--------------------------------------------------------------------------------
1 | /* adler32.c -- compute the Adler-32 checksum of a data stream
2 | * Copyright (C) 1995-2011, 2016 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #include "zutil.h"
9 |
10 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
11 |
12 | #define BASE 65521U /* largest prime smaller than 65536 */
13 | #define NMAX 5552
14 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
15 |
16 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
17 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
18 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
19 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
20 | #define DO16(buf) DO8(buf,0); DO8(buf,8);
21 |
22 | /* use NO_DIVIDE if your processor does not do division in hardware --
23 | try it both ways to see which is faster */
24 | #ifdef NO_DIVIDE
25 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15
26 | (thank you to John Reiser for pointing this out) */
27 | # define CHOP(a) \
28 | do { \
29 | unsigned long tmp = a >> 16; \
30 | a &= 0xffffUL; \
31 | a += (tmp << 4) - tmp; \
32 | } while (0)
33 | # define MOD28(a) \
34 | do { \
35 | CHOP(a); \
36 | if (a >= BASE) a -= BASE; \
37 | } while (0)
38 | # define MOD(a) \
39 | do { \
40 | CHOP(a); \
41 | MOD28(a); \
42 | } while (0)
43 | # define MOD63(a) \
44 | do { /* this assumes a is not negative */ \
45 | z_off64_t tmp = a >> 32; \
46 | a &= 0xffffffffL; \
47 | a += (tmp << 8) - (tmp << 5) + tmp; \
48 | tmp = a >> 16; \
49 | a &= 0xffffL; \
50 | a += (tmp << 4) - tmp; \
51 | tmp = a >> 16; \
52 | a &= 0xffffL; \
53 | a += (tmp << 4) - tmp; \
54 | if (a >= BASE) a -= BASE; \
55 | } while (0)
56 | #else
57 | # define MOD(a) a %= BASE
58 | # define MOD28(a) a %= BASE
59 | # define MOD63(a) a %= BASE
60 | #endif
61 |
62 | /* ========================================================================= */
63 | uLong ZEXPORT adler32_z(adler, buf, len)
64 | uLong adler;
65 | const Bytef *buf;
66 | z_size_t len;
67 | {
68 | unsigned long sum2;
69 | unsigned n;
70 |
71 | /* split Adler-32 into component sums */
72 | sum2 = (adler >> 16) & 0xffff;
73 | adler &= 0xffff;
74 |
75 | /* in case user likes doing a byte at a time, keep it fast */
76 | if (len == 1) {
77 | adler += buf[0];
78 | if (adler >= BASE)
79 | adler -= BASE;
80 | sum2 += adler;
81 | if (sum2 >= BASE)
82 | sum2 -= BASE;
83 | return adler | (sum2 << 16);
84 | }
85 |
86 | /* initial Adler-32 value (deferred check for len == 1 speed) */
87 | if (buf == Z_NULL)
88 | return 1L;
89 |
90 | /* in case short lengths are provided, keep it somewhat fast */
91 | if (len < 16) {
92 | while (len--) {
93 | adler += *buf++;
94 | sum2 += adler;
95 | }
96 | if (adler >= BASE)
97 | adler -= BASE;
98 | MOD28(sum2); /* only added so many BASE's */
99 | return adler | (sum2 << 16);
100 | }
101 |
102 | /* do length NMAX blocks -- requires just one modulo operation */
103 | while (len >= NMAX) {
104 | len -= NMAX;
105 | n = NMAX / 16; /* NMAX is divisible by 16 */
106 | do {
107 | DO16(buf); /* 16 sums unrolled */
108 | buf += 16;
109 | } while (--n);
110 | MOD(adler);
111 | MOD(sum2);
112 | }
113 |
114 | /* do remaining bytes (less than NMAX, still just one modulo) */
115 | if (len) { /* avoid modulos if none remaining */
116 | while (len >= 16) {
117 | len -= 16;
118 | DO16(buf);
119 | buf += 16;
120 | }
121 | while (len--) {
122 | adler += *buf++;
123 | sum2 += adler;
124 | }
125 | MOD(adler);
126 | MOD(sum2);
127 | }
128 |
129 | /* return recombined sums */
130 | return adler | (sum2 << 16);
131 | }
132 |
133 | /* ========================================================================= */
134 | uLong ZEXPORT adler32(adler, buf, len)
135 | uLong adler;
136 | const Bytef *buf;
137 | uInt len;
138 | {
139 | return adler32_z(adler, buf, len);
140 | }
141 |
142 | /* ========================================================================= */
143 | local uLong adler32_combine_(adler1, adler2, len2)
144 | uLong adler1;
145 | uLong adler2;
146 | z_off64_t len2;
147 | {
148 | unsigned long sum1;
149 | unsigned long sum2;
150 | unsigned rem;
151 |
152 | /* for negative len, return invalid adler32 as a clue for debugging */
153 | if (len2 < 0)
154 | return 0xffffffffUL;
155 |
156 | /* the derivation of this formula is left as an exercise for the reader */
157 | MOD63(len2); /* assumes len2 >= 0 */
158 | rem = (unsigned)len2;
159 | sum1 = adler1 & 0xffff;
160 | sum2 = rem * sum1;
161 | MOD(sum2);
162 | sum1 += (adler2 & 0xffff) + BASE - 1;
163 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
164 | if (sum1 >= BASE) sum1 -= BASE;
165 | if (sum1 >= BASE) sum1 -= BASE;
166 | if (sum2 >= ((unsigned long)BASE << 1)) sum2 -= ((unsigned long)BASE << 1);
167 | if (sum2 >= BASE) sum2 -= BASE;
168 | return sum1 | (sum2 << 16);
169 | }
170 |
171 | /* ========================================================================= */
172 | uLong ZEXPORT adler32_combine(adler1, adler2, len2)
173 | uLong adler1;
174 | uLong adler2;
175 | z_off_t len2;
176 | {
177 | return adler32_combine_(adler1, adler2, len2);
178 | }
179 |
180 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
181 | uLong adler1;
182 | uLong adler2;
183 | z_off64_t len2;
184 | {
185 | return adler32_combine_(adler1, adler2, len2);
186 | }
187 |
--------------------------------------------------------------------------------
/zlib/compress.c:
--------------------------------------------------------------------------------
1 | /* compress.c -- compress a memory buffer
2 | * Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #define ZLIB_INTERNAL
9 | #include "zlib.h"
10 |
11 | /* ===========================================================================
12 | Compresses the source buffer into the destination buffer. The level
13 | parameter has the same meaning as in deflateInit. sourceLen is the byte
14 | length of the source buffer. Upon entry, destLen is the total size of the
15 | destination buffer, which must be at least 0.1% larger than sourceLen plus
16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
17 |
18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer,
20 | Z_STREAM_ERROR if the level parameter is invalid.
21 | */
22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
23 | Bytef *dest;
24 | uLongf *destLen;
25 | const Bytef *source;
26 | uLong sourceLen;
27 | int level;
28 | {
29 | z_stream stream;
30 | int err;
31 | const uInt max = (uInt)-1;
32 | uLong left;
33 |
34 | left = *destLen;
35 | *destLen = 0;
36 |
37 | stream.zalloc = (alloc_func)0;
38 | stream.zfree = (free_func)0;
39 | stream.opaque = (voidpf)0;
40 |
41 | err = deflateInit(&stream, level);
42 | if (err != Z_OK) return err;
43 |
44 | stream.next_out = dest;
45 | stream.avail_out = 0;
46 | stream.next_in = (z_const Bytef *)source;
47 | stream.avail_in = 0;
48 |
49 | do {
50 | if (stream.avail_out == 0) {
51 | stream.avail_out = left > (uLong)max ? max : (uInt)left;
52 | left -= stream.avail_out;
53 | }
54 | if (stream.avail_in == 0) {
55 | stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
56 | sourceLen -= stream.avail_in;
57 | }
58 | err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
59 | } while (err == Z_OK);
60 |
61 | *destLen = stream.total_out;
62 | deflateEnd(&stream);
63 | return err == Z_STREAM_END ? Z_OK : err;
64 | }
65 |
66 | /* ===========================================================================
67 | */
68 | int ZEXPORT compress (dest, destLen, source, sourceLen)
69 | Bytef *dest;
70 | uLongf *destLen;
71 | const Bytef *source;
72 | uLong sourceLen;
73 | {
74 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
75 | }
76 |
77 | /* ===========================================================================
78 | If the default memLevel or windowBits for deflateInit() is changed, then
79 | this function needs to be updated.
80 | */
81 | uLong ZEXPORT compressBound (sourceLen)
82 | uLong sourceLen;
83 | {
84 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
85 | (sourceLen >> 25) + 13;
86 | }
87 |
--------------------------------------------------------------------------------
/zlib/crc32.c:
--------------------------------------------------------------------------------
1 | /* crc32.c -- compute the CRC-32 of a data stream
2 | * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | *
5 | * Thanks to Rodney Brown for his contribution of faster
6 | * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
7 | * tables for updating the shift register in one step with three exclusive-ors
8 | * instead of four steps with four exclusive-ors. This results in about a
9 | * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
10 | */
11 |
12 | /* @(#) $Id$ */
13 |
14 | /*
15 | Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
16 | protection on the static variables used to control the first-use generation
17 | of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
18 | first call get_crc_table() to initialize the tables before allowing more than
19 | one thread to use crc32().
20 |
21 | DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h.
22 | */
23 |
24 | #ifdef MAKECRCH
25 | # include
26 | # ifndef DYNAMIC_CRC_TABLE
27 | # define DYNAMIC_CRC_TABLE
28 | # endif /* !DYNAMIC_CRC_TABLE */
29 | #endif /* MAKECRCH */
30 |
31 | #include "zutil.h" /* for STDC and FAR definitions */
32 |
33 | /* Definitions for doing the crc four data bytes at a time. */
34 | #if !defined(NOBYFOUR) && defined(Z_U4)
35 | # define BYFOUR
36 | #endif
37 | #ifdef BYFOUR
38 | local unsigned long crc32_little OF((unsigned long,
39 | const unsigned char FAR *, z_size_t));
40 | local unsigned long crc32_big OF((unsigned long,
41 | const unsigned char FAR *, z_size_t));
42 | # define TBLS 8
43 | #else
44 | # define TBLS 1
45 | #endif /* BYFOUR */
46 |
47 | /* Local functions for crc concatenation */
48 | local unsigned long gf2_matrix_times OF((unsigned long *mat,
49 | unsigned long vec));
50 | local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
51 | local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2));
52 |
53 |
54 | #ifdef DYNAMIC_CRC_TABLE
55 |
56 | local volatile int crc_table_empty = 1;
57 | local z_crc_t FAR crc_table[TBLS][256];
58 | local void make_crc_table OF((void));
59 | #ifdef MAKECRCH
60 | local void write_table OF((FILE *, const z_crc_t FAR *));
61 | #endif /* MAKECRCH */
62 | /*
63 | Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
64 | x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
65 |
66 | Polynomials over GF(2) are represented in binary, one bit per coefficient,
67 | with the lowest powers in the most significant bit. Then adding polynomials
68 | is just exclusive-or, and multiplying a polynomial by x is a right shift by
69 | one. If we call the above polynomial p, and represent a byte as the
70 | polynomial q, also with the lowest power in the most significant bit (so the
71 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
72 | where a mod b means the remainder after dividing a by b.
73 |
74 | This calculation is done using the shift-register method of multiplying and
75 | taking the remainder. The register is initialized to zero, and for each
76 | incoming bit, x^32 is added mod p to the register if the bit is a one (where
77 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
78 | x (which is shifting right by one and adding x^32 mod p if the bit shifted
79 | out is a one). We start with the highest power (least significant bit) of
80 | q and repeat for all eight bits of q.
81 |
82 | The first table is simply the CRC of all possible eight bit values. This is
83 | all the information needed to generate CRCs on data a byte at a time for all
84 | combinations of CRC register values and incoming bytes. The remaining tables
85 | allow for word-at-a-time CRC calculation for both big-endian and little-
86 | endian machines, where a word is four bytes.
87 | */
88 | local void make_crc_table()
89 | {
90 | z_crc_t c;
91 | int n, k;
92 | z_crc_t poly; /* polynomial exclusive-or pattern */
93 | /* terms of polynomial defining this crc (except x^32): */
94 | static volatile int first = 1; /* flag to limit concurrent making */
95 | static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
96 |
97 | /* See if another task is already doing this (not thread-safe, but better
98 | than nothing -- significantly reduces duration of vulnerability in
99 | case the advice about DYNAMIC_CRC_TABLE is ignored) */
100 | if (first) {
101 | first = 0;
102 |
103 | /* make exclusive-or pattern from polynomial (0xedb88320UL) */
104 | poly = 0;
105 | for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++)
106 | poly |= (z_crc_t)1 << (31 - p[n]);
107 |
108 | /* generate a crc for every 8-bit value */
109 | for (n = 0; n < 256; n++) {
110 | c = (z_crc_t)n;
111 | for (k = 0; k < 8; k++)
112 | c = c & 1 ? poly ^ (c >> 1) : c >> 1;
113 | crc_table[0][n] = c;
114 | }
115 |
116 | #ifdef BYFOUR
117 | /* generate crc for each value followed by one, two, and three zeros,
118 | and then the byte reversal of those as well as the first table */
119 | for (n = 0; n < 256; n++) {
120 | c = crc_table[0][n];
121 | crc_table[4][n] = ZSWAP32(c);
122 | for (k = 1; k < 4; k++) {
123 | c = crc_table[0][c & 0xff] ^ (c >> 8);
124 | crc_table[k][n] = c;
125 | crc_table[k + 4][n] = ZSWAP32(c);
126 | }
127 | }
128 | #endif /* BYFOUR */
129 |
130 | crc_table_empty = 0;
131 | }
132 | else { /* not first */
133 | /* wait for the other guy to finish (not efficient, but rare) */
134 | while (crc_table_empty)
135 | ;
136 | }
137 |
138 | #ifdef MAKECRCH
139 | /* write out CRC tables to crc32.h */
140 | {
141 | FILE *out;
142 |
143 | out = fopen("crc32.h", "w");
144 | if (out == NULL) return;
145 | fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
146 | fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
147 | fprintf(out, "local const z_crc_t FAR ");
148 | fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
149 | write_table(out, crc_table[0]);
150 | # ifdef BYFOUR
151 | fprintf(out, "#ifdef BYFOUR\n");
152 | for (k = 1; k < 8; k++) {
153 | fprintf(out, " },\n {\n");
154 | write_table(out, crc_table[k]);
155 | }
156 | fprintf(out, "#endif\n");
157 | # endif /* BYFOUR */
158 | fprintf(out, " }\n};\n");
159 | fclose(out);
160 | }
161 | #endif /* MAKECRCH */
162 | }
163 |
164 | #ifdef MAKECRCH
165 | local void write_table(out, table)
166 | FILE *out;
167 | const z_crc_t FAR *table;
168 | {
169 | int n;
170 |
171 | for (n = 0; n < 256; n++)
172 | fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ",
173 | (unsigned long)(table[n]),
174 | n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
175 | }
176 | #endif /* MAKECRCH */
177 |
178 | #else /* !DYNAMIC_CRC_TABLE */
179 | /* ========================================================================
180 | * Tables of CRC-32s of all single-byte values, made by make_crc_table().
181 | */
182 | #include "crc32.h"
183 | #endif /* DYNAMIC_CRC_TABLE */
184 |
185 | /* =========================================================================
186 | * This function can be used by asm versions of crc32()
187 | */
188 | const z_crc_t FAR * ZEXPORT get_crc_table()
189 | {
190 | #ifdef DYNAMIC_CRC_TABLE
191 | if (crc_table_empty)
192 | make_crc_table();
193 | #endif /* DYNAMIC_CRC_TABLE */
194 | return (const z_crc_t FAR *)crc_table;
195 | }
196 |
197 | /* ========================================================================= */
198 | #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
199 | #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
200 |
201 | /* ========================================================================= */
202 | unsigned long ZEXPORT crc32_z(crc, buf, len)
203 | unsigned long crc;
204 | const unsigned char FAR *buf;
205 | z_size_t len;
206 | {
207 | if (buf == Z_NULL) return 0UL;
208 |
209 | #ifdef DYNAMIC_CRC_TABLE
210 | if (crc_table_empty)
211 | make_crc_table();
212 | #endif /* DYNAMIC_CRC_TABLE */
213 |
214 | #ifdef BYFOUR
215 | if (sizeof(void *) == sizeof(ptrdiff_t)) {
216 | z_crc_t endian;
217 |
218 | endian = 1;
219 | if (*((unsigned char *)(&endian)))
220 | return crc32_little(crc, buf, len);
221 | else
222 | return crc32_big(crc, buf, len);
223 | }
224 | #endif /* BYFOUR */
225 | crc = crc ^ 0xffffffffUL;
226 | while (len >= 8) {
227 | DO8;
228 | len -= 8;
229 | }
230 | if (len) do {
231 | DO1;
232 | } while (--len);
233 | return crc ^ 0xffffffffUL;
234 | }
235 |
236 | /* ========================================================================= */
237 | unsigned long ZEXPORT crc32(crc, buf, len)
238 | unsigned long crc;
239 | const unsigned char FAR *buf;
240 | uInt len;
241 | {
242 | return crc32_z(crc, buf, len);
243 | }
244 |
245 | #ifdef BYFOUR
246 |
247 | /*
248 | This BYFOUR code accesses the passed unsigned char * buffer with a 32-bit
249 | integer pointer type. This violates the strict aliasing rule, where a
250 | compiler can assume, for optimization purposes, that two pointers to
251 | fundamentally different types won't ever point to the same memory. This can
252 | manifest as a problem only if one of the pointers is written to. This code
253 | only reads from those pointers. So long as this code remains isolated in
254 | this compilation unit, there won't be a problem. For this reason, this code
255 | should not be copied and pasted into a compilation unit in which other code
256 | writes to the buffer that is passed to these routines.
257 | */
258 |
259 | /* ========================================================================= */
260 | #define DOLIT4 c ^= *buf4++; \
261 | c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
262 | crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
263 | #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
264 |
265 | /* ========================================================================= */
266 | local unsigned long crc32_little(crc, buf, len)
267 | unsigned long crc;
268 | const unsigned char FAR *buf;
269 | z_size_t len;
270 | {
271 | register z_crc_t c;
272 | register const z_crc_t FAR *buf4;
273 |
274 | c = (z_crc_t)crc;
275 | c = ~c;
276 | while (len && ((ptrdiff_t)buf & 3)) {
277 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
278 | len--;
279 | }
280 |
281 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
282 | while (len >= 32) {
283 | DOLIT32;
284 | len -= 32;
285 | }
286 | while (len >= 4) {
287 | DOLIT4;
288 | len -= 4;
289 | }
290 | buf = (const unsigned char FAR *)buf4;
291 |
292 | if (len) do {
293 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
294 | } while (--len);
295 | c = ~c;
296 | return (unsigned long)c;
297 | }
298 |
299 | /* ========================================================================= */
300 | #define DOBIG4 c ^= *buf4++; \
301 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
302 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
303 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
304 |
305 | /* ========================================================================= */
306 | local unsigned long crc32_big(crc, buf, len)
307 | unsigned long crc;
308 | const unsigned char FAR *buf;
309 | z_size_t len;
310 | {
311 | register z_crc_t c;
312 | register const z_crc_t FAR *buf4;
313 |
314 | c = ZSWAP32((z_crc_t)crc);
315 | c = ~c;
316 | while (len && ((ptrdiff_t)buf & 3)) {
317 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
318 | len--;
319 | }
320 |
321 | buf4 = (const z_crc_t FAR *)(const void FAR *)buf;
322 | while (len >= 32) {
323 | DOBIG32;
324 | len -= 32;
325 | }
326 | while (len >= 4) {
327 | DOBIG4;
328 | len -= 4;
329 | }
330 | buf = (const unsigned char FAR *)buf4;
331 |
332 | if (len) do {
333 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
334 | } while (--len);
335 | c = ~c;
336 | return (unsigned long)(ZSWAP32(c));
337 | }
338 |
339 | #endif /* BYFOUR */
340 |
341 | #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
342 |
343 | /* ========================================================================= */
344 | local unsigned long gf2_matrix_times(mat, vec)
345 | unsigned long *mat;
346 | unsigned long vec;
347 | {
348 | unsigned long sum;
349 |
350 | sum = 0;
351 | while (vec) {
352 | if (vec & 1)
353 | sum ^= *mat;
354 | vec >>= 1;
355 | mat++;
356 | }
357 | return sum;
358 | }
359 |
360 | /* ========================================================================= */
361 | local void gf2_matrix_square(square, mat)
362 | unsigned long *square;
363 | unsigned long *mat;
364 | {
365 | int n;
366 |
367 | for (n = 0; n < GF2_DIM; n++)
368 | square[n] = gf2_matrix_times(mat, mat[n]);
369 | }
370 |
371 | /* ========================================================================= */
372 | local uLong crc32_combine_(crc1, crc2, len2)
373 | uLong crc1;
374 | uLong crc2;
375 | z_off64_t len2;
376 | {
377 | int n;
378 | unsigned long row;
379 | unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
380 | unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
381 |
382 | /* degenerate case (also disallow negative lengths) */
383 | if (len2 <= 0)
384 | return crc1;
385 |
386 | /* put operator for one zero bit in odd */
387 | odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
388 | row = 1;
389 | for (n = 1; n < GF2_DIM; n++) {
390 | odd[n] = row;
391 | row <<= 1;
392 | }
393 |
394 | /* put operator for two zero bits in even */
395 | gf2_matrix_square(even, odd);
396 |
397 | /* put operator for four zero bits in odd */
398 | gf2_matrix_square(odd, even);
399 |
400 | /* apply len2 zeros to crc1 (first square will put the operator for one
401 | zero byte, eight zero bits, in even) */
402 | do {
403 | /* apply zeros operator for this bit of len2 */
404 | gf2_matrix_square(even, odd);
405 | if (len2 & 1)
406 | crc1 = gf2_matrix_times(even, crc1);
407 | len2 >>= 1;
408 |
409 | /* if no more bits set, then done */
410 | if (len2 == 0)
411 | break;
412 |
413 | /* another iteration of the loop with odd and even swapped */
414 | gf2_matrix_square(odd, even);
415 | if (len2 & 1)
416 | crc1 = gf2_matrix_times(odd, crc1);
417 | len2 >>= 1;
418 |
419 | /* if no more bits set, then done */
420 | } while (len2 != 0);
421 |
422 | /* return combined crc */
423 | crc1 ^= crc2;
424 | return crc1;
425 | }
426 |
427 | /* ========================================================================= */
428 | uLong ZEXPORT crc32_combine(crc1, crc2, len2)
429 | uLong crc1;
430 | uLong crc2;
431 | z_off_t len2;
432 | {
433 | return crc32_combine_(crc1, crc2, len2);
434 | }
435 |
436 | uLong ZEXPORT crc32_combine64(crc1, crc2, len2)
437 | uLong crc1;
438 | uLong crc2;
439 | z_off64_t len2;
440 | {
441 | return crc32_combine_(crc1, crc2, len2);
442 | }
443 |
--------------------------------------------------------------------------------
/zlib/deflate.h:
--------------------------------------------------------------------------------
1 | /* deflate.h -- internal compression state
2 | * Copyright (C) 1995-2016 Jean-loup Gailly
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* @(#) $Id$ */
12 |
13 | #ifndef DEFLATE_H
14 | #define DEFLATE_H
15 |
16 | #include "zutil.h"
17 |
18 | /* define NO_GZIP when compiling if you want to disable gzip header and
19 | trailer creation by deflate(). NO_GZIP would be used to avoid linking in
20 | the crc code when it is not needed. For shared libraries, gzip encoding
21 | should be left enabled. */
22 | #ifndef NO_GZIP
23 | # define GZIP
24 | #endif
25 |
26 | /* ===========================================================================
27 | * Internal compression state.
28 | */
29 |
30 | #define LENGTH_CODES 29
31 | /* number of length codes, not counting the special END_BLOCK code */
32 |
33 | #define LITERALS 256
34 | /* number of literal bytes 0..255 */
35 |
36 | #define L_CODES (LITERALS+1+LENGTH_CODES)
37 | /* number of Literal or Length codes, including the END_BLOCK code */
38 |
39 | #define D_CODES 30
40 | /* number of distance codes */
41 |
42 | #define BL_CODES 19
43 | /* number of codes used to transfer the bit lengths */
44 |
45 | #define HEAP_SIZE (2*L_CODES+1)
46 | /* maximum heap size */
47 |
48 | #define MAX_BITS 15
49 | /* All codes must not exceed MAX_BITS bits */
50 |
51 | #define Buf_size 16
52 | /* size of bit buffer in bi_buf */
53 |
54 | #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
55 | #ifdef GZIP
56 | # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
57 | #endif
58 | #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
59 | #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
60 | #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
61 | #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
62 | #define BUSY_STATE 113 /* deflate -> FINISH_STATE */
63 | #define FINISH_STATE 666 /* stream complete */
64 | /* Stream status */
65 |
66 |
67 | /* Data structure describing a single value and its code string. */
68 | typedef struct ct_data_s {
69 | union {
70 | ush freq; /* frequency count */
71 | ush code; /* bit string */
72 | } fc;
73 | union {
74 | ush dad; /* father node in Huffman tree */
75 | ush len; /* length of bit string */
76 | } dl;
77 | } FAR ct_data;
78 |
79 | #define Freq fc.freq
80 | #define Code fc.code
81 | #define Dad dl.dad
82 | #define Len dl.len
83 |
84 | typedef struct static_tree_desc_s static_tree_desc;
85 |
86 | typedef struct tree_desc_s {
87 | ct_data *dyn_tree; /* the dynamic tree */
88 | int max_code; /* largest code with non zero frequency */
89 | const static_tree_desc *stat_desc; /* the corresponding static tree */
90 | } FAR tree_desc;
91 |
92 | typedef ush Pos;
93 | typedef Pos FAR Posf;
94 | typedef unsigned IPos;
95 |
96 | /* A Pos is an index in the character window. We use short instead of int to
97 | * save space in the various tables. IPos is used only for parameter passing.
98 | */
99 |
100 | typedef struct internal_state {
101 | z_streamp strm; /* pointer back to this zlib stream */
102 | int status; /* as the name implies */
103 | Bytef *pending_buf; /* output still pending */
104 | ulg pending_buf_size; /* size of pending_buf */
105 | Bytef *pending_out; /* next pending byte to output to the stream */
106 | ulg pending; /* nb of bytes in the pending buffer */
107 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
108 | gz_headerp gzhead; /* gzip header information to write */
109 | ulg gzindex; /* where in extra, name, or comment */
110 | Byte method; /* can only be DEFLATED */
111 | int last_flush; /* value of flush param for previous deflate call */
112 |
113 | /* used by deflate.c: */
114 |
115 | uInt w_size; /* LZ77 window size (32K by default) */
116 | uInt w_bits; /* log2(w_size) (8..16) */
117 | uInt w_mask; /* w_size - 1 */
118 |
119 | Bytef *window;
120 | /* Sliding window. Input bytes are read into the second half of the window,
121 | * and move to the first half later to keep a dictionary of at least wSize
122 | * bytes. With this organization, matches are limited to a distance of
123 | * wSize-MAX_MATCH bytes, but this ensures that IO is always
124 | * performed with a length multiple of the block size. Also, it limits
125 | * the window size to 64K, which is quite useful on MSDOS.
126 | * To do: use the user input buffer as sliding window.
127 | */
128 |
129 | ulg window_size;
130 | /* Actual size of window: 2*wSize, except when the user input buffer
131 | * is directly used as sliding window.
132 | */
133 |
134 | Posf *prev;
135 | /* Link to older string with same hash index. To limit the size of this
136 | * array to 64K, this link is maintained only for the last 32K strings.
137 | * An index in this array is thus a window index modulo 32K.
138 | */
139 |
140 | Posf *head; /* Heads of the hash chains or NIL. */
141 |
142 | uInt ins_h; /* hash index of string to be inserted */
143 | uInt hash_size; /* number of elements in hash table */
144 | uInt hash_bits; /* log2(hash_size) */
145 | uInt hash_mask; /* hash_size-1 */
146 |
147 | uInt hash_shift;
148 | /* Number of bits by which ins_h must be shifted at each input
149 | * step. It must be such that after MIN_MATCH steps, the oldest
150 | * byte no longer takes part in the hash key, that is:
151 | * hash_shift * MIN_MATCH >= hash_bits
152 | */
153 |
154 | long block_start;
155 | /* Window position at the beginning of the current output block. Gets
156 | * negative when the window is moved backwards.
157 | */
158 |
159 | uInt match_length; /* length of best match */
160 | IPos prev_match; /* previous match */
161 | int match_available; /* set if previous match exists */
162 | uInt strstart; /* start of string to insert */
163 | uInt match_start; /* start of matching string */
164 | uInt lookahead; /* number of valid bytes ahead in window */
165 |
166 | uInt prev_length;
167 | /* Length of the best match at previous step. Matches not greater than this
168 | * are discarded. This is used in the lazy match evaluation.
169 | */
170 |
171 | uInt max_chain_length;
172 | /* To speed up deflation, hash chains are never searched beyond this
173 | * length. A higher limit improves compression ratio but degrades the
174 | * speed.
175 | */
176 |
177 | uInt max_lazy_match;
178 | /* Attempt to find a better match only when the current match is strictly
179 | * smaller than this value. This mechanism is used only for compression
180 | * levels >= 4.
181 | */
182 | # define max_insert_length max_lazy_match
183 | /* Insert new strings in the hash table only if the match length is not
184 | * greater than this length. This saves time but degrades compression.
185 | * max_insert_length is used only for compression levels <= 3.
186 | */
187 |
188 | int level; /* compression level (1..9) */
189 | int strategy; /* favor or force Huffman coding*/
190 |
191 | uInt good_match;
192 | /* Use a faster search when the previous match is longer than this */
193 |
194 | int nice_match; /* Stop searching when current match exceeds this */
195 |
196 | /* used by trees.c: */
197 | /* Didn't use ct_data typedef below to suppress compiler warning */
198 | struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
199 | struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
200 | struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
201 |
202 | struct tree_desc_s l_desc; /* desc. for literal tree */
203 | struct tree_desc_s d_desc; /* desc. for distance tree */
204 | struct tree_desc_s bl_desc; /* desc. for bit length tree */
205 |
206 | ush bl_count[MAX_BITS+1];
207 | /* number of codes at each bit length for an optimal tree */
208 |
209 | int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
210 | int heap_len; /* number of elements in the heap */
211 | int heap_max; /* element of largest frequency */
212 | /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
213 | * The same heap array is used to build all trees.
214 | */
215 |
216 | uch depth[2*L_CODES+1];
217 | /* Depth of each subtree used as tie breaker for trees of equal frequency
218 | */
219 |
220 | uchf *l_buf; /* buffer for literals or lengths */
221 |
222 | uInt lit_bufsize;
223 | /* Size of match buffer for literals/lengths. There are 4 reasons for
224 | * limiting lit_bufsize to 64K:
225 | * - frequencies can be kept in 16 bit counters
226 | * - if compression is not successful for the first block, all input
227 | * data is still in the window so we can still emit a stored block even
228 | * when input comes from standard input. (This can also be done for
229 | * all blocks if lit_bufsize is not greater than 32K.)
230 | * - if compression is not successful for a file smaller than 64K, we can
231 | * even emit a stored file instead of a stored block (saving 5 bytes).
232 | * This is applicable only for zip (not gzip or zlib).
233 | * - creating new Huffman trees less frequently may not provide fast
234 | * adaptation to changes in the input data statistics. (Take for
235 | * example a binary file with poorly compressible code followed by
236 | * a highly compressible string table.) Smaller buffer sizes give
237 | * fast adaptation but have of course the overhead of transmitting
238 | * trees more frequently.
239 | * - I can't count above 4
240 | */
241 |
242 | uInt last_lit; /* running index in l_buf */
243 |
244 | ushf *d_buf;
245 | /* Buffer for distances. To simplify the code, d_buf and l_buf have
246 | * the same number of elements. To use different lengths, an extra flag
247 | * array would be necessary.
248 | */
249 |
250 | ulg opt_len; /* bit length of current block with optimal trees */
251 | ulg static_len; /* bit length of current block with static trees */
252 | uInt matches; /* number of string matches in current block */
253 | uInt insert; /* bytes at end of window left to insert */
254 |
255 | #ifdef ZLIB_DEBUG
256 | ulg compressed_len; /* total bit length of compressed file mod 2^32 */
257 | ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
258 | #endif
259 |
260 | ush bi_buf;
261 | /* Output buffer. bits are inserted starting at the bottom (least
262 | * significant bits).
263 | */
264 | int bi_valid;
265 | /* Number of valid bits in bi_buf. All bits above the last valid bit
266 | * are always zero.
267 | */
268 |
269 | ulg high_water;
270 | /* High water mark offset in window for initialized bytes -- bytes above
271 | * this are set to zero in order to avoid memory check warnings when
272 | * longest match routines access bytes past the input. This is then
273 | * updated to the new high water mark.
274 | */
275 |
276 | } FAR deflate_state;
277 |
278 | /* Output a byte on the stream.
279 | * IN assertion: there is enough room in pending_buf.
280 | */
281 | #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
282 |
283 |
284 | #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
285 | /* Minimum amount of lookahead, except at the end of the input file.
286 | * See deflate.c for comments about the MIN_MATCH+1.
287 | */
288 |
289 | #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
290 | /* In order to simplify the code, particularly on 16 bit machines, match
291 | * distances are limited to MAX_DIST instead of WSIZE.
292 | */
293 |
294 | #define WIN_INIT MAX_MATCH
295 | /* Number of bytes after end of data in window to initialize in order to avoid
296 | memory checker errors from longest match routines */
297 |
298 | /* in trees.c */
299 | void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
300 | int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
301 | void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
302 | ulg stored_len, int last));
303 | void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
304 | void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
305 | void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
306 | ulg stored_len, int last));
307 |
308 | #define d_code(dist) \
309 | ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
310 | /* Mapping from a distance to a distance code. dist is the distance - 1 and
311 | * must not have side effects. _dist_code[256] and _dist_code[257] are never
312 | * used.
313 | */
314 |
315 | #ifndef ZLIB_DEBUG
316 | /* Inline versions of _tr_tally for speed: */
317 |
318 | #if defined(GEN_TREES_H) || !defined(STDC)
319 | extern uch ZLIB_INTERNAL _length_code[];
320 | extern uch ZLIB_INTERNAL _dist_code[];
321 | #else
322 | extern const uch ZLIB_INTERNAL _length_code[];
323 | extern const uch ZLIB_INTERNAL _dist_code[];
324 | #endif
325 |
326 | # define _tr_tally_lit(s, c, flush) \
327 | { uch cc = (c); \
328 | s->d_buf[s->last_lit] = 0; \
329 | s->l_buf[s->last_lit++] = cc; \
330 | s->dyn_ltree[cc].Freq++; \
331 | flush = (s->last_lit == s->lit_bufsize-1); \
332 | }
333 | # define _tr_tally_dist(s, distance, length, flush) \
334 | { uch len = (uch)(length); \
335 | ush dist = (ush)(distance); \
336 | s->d_buf[s->last_lit] = dist; \
337 | s->l_buf[s->last_lit++] = len; \
338 | dist--; \
339 | s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
340 | s->dyn_dtree[d_code(dist)].Freq++; \
341 | flush = (s->last_lit == s->lit_bufsize-1); \
342 | }
343 | #else
344 | # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
345 | # define _tr_tally_dist(s, distance, length, flush) \
346 | flush = _tr_tally(s, distance, length)
347 | #endif
348 |
349 | #endif /* DEFLATE_H */
350 |
--------------------------------------------------------------------------------
/zlib/gzclose.c:
--------------------------------------------------------------------------------
1 | /* gzclose.c -- zlib gzclose() function
2 | * Copyright (C) 2004, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #include "gzguts.h"
7 |
8 | /* gzclose() is in a separate file so that it is linked in only if it is used.
9 | That way the other gzclose functions can be used instead to avoid linking in
10 | unneeded compression or decompression routines. */
11 | int ZEXPORT gzclose(file)
12 | gzFile file;
13 | {
14 | #ifndef NO_GZCOMPRESS
15 | gz_statep state;
16 |
17 | if (file == NULL)
18 | return Z_STREAM_ERROR;
19 | state = (gz_statep)file;
20 |
21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
22 | #else
23 | return gzclose_r(file);
24 | #endif
25 | }
26 |
--------------------------------------------------------------------------------
/zlib/gzguts.h:
--------------------------------------------------------------------------------
1 | /* gzguts.h -- zlib internal header definitions for gz* operations
2 | * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #ifdef _LARGEFILE64_SOURCE
7 | # ifndef _LARGEFILE_SOURCE
8 | # define _LARGEFILE_SOURCE 1
9 | # endif
10 | # ifdef _FILE_OFFSET_BITS
11 | # undef _FILE_OFFSET_BITS
12 | # endif
13 | #endif
14 |
15 | #ifdef HAVE_HIDDEN
16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
17 | #else
18 | # define ZLIB_INTERNAL
19 | #endif
20 |
21 | #include
22 | #include "zlib.h"
23 | #ifdef STDC
24 | # include
25 | # include
26 | # include
27 | #endif
28 |
29 | #ifndef _POSIX_SOURCE
30 | # define _POSIX_SOURCE
31 | #endif
32 | #include
33 |
34 | #ifdef _WIN32
35 | # include
36 | #endif
37 |
38 | #if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
39 | # include
40 | #endif
41 |
42 | #if defined(_WIN32) || defined(__CYGWIN__)
43 | # define WIDECHAR
44 | #endif
45 |
46 | #ifdef WINAPI_FAMILY
47 | # define open _open
48 | # define read _read
49 | # define write _write
50 | # define close _close
51 | #endif
52 |
53 | #ifdef NO_DEFLATE /* for compatibility with old definition */
54 | # define NO_GZCOMPRESS
55 | #endif
56 |
57 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
58 | # ifndef HAVE_VSNPRINTF
59 | # define HAVE_VSNPRINTF
60 | # endif
61 | #endif
62 |
63 | #if defined(__CYGWIN__)
64 | # ifndef HAVE_VSNPRINTF
65 | # define HAVE_VSNPRINTF
66 | # endif
67 | #endif
68 |
69 | #if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
70 | # ifndef HAVE_VSNPRINTF
71 | # define HAVE_VSNPRINTF
72 | # endif
73 | #endif
74 |
75 | #ifndef HAVE_VSNPRINTF
76 | # ifdef MSDOS
77 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
78 | but for now we just assume it doesn't. */
79 | # define NO_vsnprintf
80 | # endif
81 | # ifdef __TURBOC__
82 | # define NO_vsnprintf
83 | # endif
84 | # ifdef WIN32
85 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
86 | # if !defined(vsnprintf) && !defined(NO_vsnprintf)
87 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
88 | # define vsnprintf _vsnprintf
89 | # endif
90 | # endif
91 | # endif
92 | # ifdef __SASC
93 | # define NO_vsnprintf
94 | # endif
95 | # ifdef VMS
96 | # define NO_vsnprintf
97 | # endif
98 | # ifdef __OS400__
99 | # define NO_vsnprintf
100 | # endif
101 | # ifdef __MVS__
102 | # define NO_vsnprintf
103 | # endif
104 | #endif
105 |
106 | /* unlike snprintf (which is required in C99), _snprintf does not guarantee
107 | null termination of the result -- however this is only used in gzlib.c where
108 | the result is assured to fit in the space provided */
109 | #if defined(_MSC_VER) && _MSC_VER < 1900
110 | # define snprintf _snprintf
111 | #endif
112 |
113 | #ifndef local
114 | # define local static
115 | #endif
116 | /* since "static" is used to mean two completely different things in C, we
117 | define "local" for the non-static meaning of "static", for readability
118 | (compile with -Dlocal if your debugger can't find static symbols) */
119 |
120 | /* gz* functions always use library allocation functions */
121 | #ifndef STDC
122 | extern voidp malloc OF((uInt size));
123 | extern void free OF((voidpf ptr));
124 | #endif
125 |
126 | /* get errno and strerror definition */
127 | #if defined UNDER_CE
128 | # include
129 | # define zstrerror() gz_strwinerror((DWORD)GetLastError())
130 | #else
131 | # ifndef NO_STRERROR
132 | # include
133 | # define zstrerror() strerror(errno)
134 | # else
135 | # define zstrerror() "stdio error (consult errno)"
136 | # endif
137 | #endif
138 |
139 | /* provide prototypes for these when building zlib without LFS */
140 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
141 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
142 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
143 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
144 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
145 | #endif
146 |
147 | /* default memLevel */
148 | #if MAX_MEM_LEVEL >= 8
149 | # define DEF_MEM_LEVEL 8
150 | #else
151 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL
152 | #endif
153 |
154 | /* default i/o buffer size -- double this for output when reading (this and
155 | twice this must be able to fit in an unsigned type) */
156 | #define GZBUFSIZE 8192
157 |
158 | /* gzip modes, also provide a little integrity check on the passed structure */
159 | #define GZ_NONE 0
160 | #define GZ_READ 7247
161 | #define GZ_WRITE 31153
162 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
163 |
164 | /* values for gz_state how */
165 | #define LOOK 0 /* look for a gzip header */
166 | #define COPY 1 /* copy input directly */
167 | #define GZIP 2 /* decompress a gzip stream */
168 |
169 | /* internal gzip file state data structure */
170 | typedef struct {
171 | /* exposed contents for gzgetc() macro */
172 | struct gzFile_s x; /* "x" for exposed */
173 | /* x.have: number of bytes available at x.next */
174 | /* x.next: next output data to deliver or write */
175 | /* x.pos: current position in uncompressed data */
176 | /* used for both reading and writing */
177 | int mode; /* see gzip modes above */
178 | int fd; /* file descriptor */
179 | char *path; /* path or fd for error messages */
180 | unsigned size; /* buffer size, zero if not allocated yet */
181 | unsigned want; /* requested buffer size, default is GZBUFSIZE */
182 | unsigned char *in; /* input buffer (double-sized when writing) */
183 | unsigned char *out; /* output buffer (double-sized when reading) */
184 | int direct; /* 0 if processing gzip, 1 if transparent */
185 | /* just for reading */
186 | int how; /* 0: get header, 1: copy, 2: decompress */
187 | z_off64_t start; /* where the gzip data started, for rewinding */
188 | int eof; /* true if end of input file reached */
189 | int past; /* true if read requested past end */
190 | /* just for writing */
191 | int level; /* compression level */
192 | int strategy; /* compression strategy */
193 | /* seek request */
194 | z_off64_t skip; /* amount to skip (already rewound if backwards) */
195 | int seek; /* true if seek request pending */
196 | /* error information */
197 | int err; /* error code */
198 | char *msg; /* error message */
199 | /* zlib inflate or deflate stream */
200 | z_stream strm; /* stream structure in-place (not a pointer) */
201 | } gz_state;
202 | typedef gz_state FAR *gz_statep;
203 |
204 | /* shared functions */
205 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
206 | #if defined UNDER_CE
207 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
208 | #endif
209 |
210 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
211 | value -- needed when comparing unsigned to z_off64_t, which is signed
212 | (possible z_off64_t types off_t, off64_t, and long are all signed) */
213 | #ifdef INT_MAX
214 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
215 | #else
216 | unsigned ZLIB_INTERNAL gz_intmax OF((void));
217 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
218 | #endif
219 |
--------------------------------------------------------------------------------
/zlib/inffast.c:
--------------------------------------------------------------------------------
1 | /* inffast.c -- fast decoding
2 | * Copyright (C) 1995-2017 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #include "zutil.h"
7 | #include "inftrees.h"
8 | #include "inflate.h"
9 | #include "inffast.h"
10 |
11 | #ifdef ASMINF
12 | # pragma message("Assembler code may have bugs -- use at your own risk")
13 | #else
14 |
15 | /*
16 | Decode literal, length, and distance codes and write out the resulting
17 | literal and match bytes until either not enough input or output is
18 | available, an end-of-block is encountered, or a data error is encountered.
19 | When large enough input and output buffers are supplied to inflate(), for
20 | example, a 16K input buffer and a 64K output buffer, more than 95% of the
21 | inflate execution time is spent in this routine.
22 |
23 | Entry assumptions:
24 |
25 | state->mode == LEN
26 | strm->avail_in >= 6
27 | strm->avail_out >= 258
28 | start >= strm->avail_out
29 | state->bits < 8
30 |
31 | On return, state->mode is one of:
32 |
33 | LEN -- ran out of enough output space or enough available input
34 | TYPE -- reached end of block code, inflate() to interpret next block
35 | BAD -- error in block data
36 |
37 | Notes:
38 |
39 | - The maximum input bits used by a length/distance pair is 15 bits for the
40 | length code, 5 bits for the length extra, 15 bits for the distance code,
41 | and 13 bits for the distance extra. This totals 48 bits, or six bytes.
42 | Therefore if strm->avail_in >= 6, then there is enough input to avoid
43 | checking for available input while decoding.
44 |
45 | - The maximum bytes that a single length/distance pair can output is 258
46 | bytes, which is the maximum length that can be coded. inflate_fast()
47 | requires strm->avail_out >= 258 for each loop to avoid checking for
48 | output space.
49 | */
50 | void ZLIB_INTERNAL inflate_fast(strm, start)
51 | z_streamp strm;
52 | unsigned start; /* inflate()'s starting value for strm->avail_out */
53 | {
54 | struct inflate_state FAR *state;
55 | z_const unsigned char FAR *in; /* local strm->next_in */
56 | z_const unsigned char FAR *last; /* have enough input while in < last */
57 | unsigned char FAR *out; /* local strm->next_out */
58 | unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
59 | unsigned char FAR *end; /* while out < end, enough space available */
60 | #ifdef INFLATE_STRICT
61 | unsigned dmax; /* maximum distance from zlib header */
62 | #endif
63 | unsigned wsize; /* window size or zero if not using window */
64 | unsigned whave; /* valid bytes in the window */
65 | unsigned wnext; /* window write index */
66 | unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
67 | unsigned long hold; /* local strm->hold */
68 | unsigned bits; /* local strm->bits */
69 | code const FAR *lcode; /* local strm->lencode */
70 | code const FAR *dcode; /* local strm->distcode */
71 | unsigned lmask; /* mask for first level of length codes */
72 | unsigned dmask; /* mask for first level of distance codes */
73 | code here; /* retrieved table entry */
74 | unsigned op; /* code bits, operation, extra bits, or */
75 | /* window position, window bytes to copy */
76 | unsigned len; /* match length, unused bytes */
77 | unsigned dist; /* match distance */
78 | unsigned char FAR *from; /* where to copy match from */
79 |
80 | /* copy state to local variables */
81 | state = (struct inflate_state FAR *)strm->state;
82 | in = strm->next_in;
83 | last = in + (strm->avail_in - 5);
84 | out = strm->next_out;
85 | beg = out - (start - strm->avail_out);
86 | end = out + (strm->avail_out - 257);
87 | #ifdef INFLATE_STRICT
88 | dmax = state->dmax;
89 | #endif
90 | wsize = state->wsize;
91 | whave = state->whave;
92 | wnext = state->wnext;
93 | window = state->window;
94 | hold = state->hold;
95 | bits = state->bits;
96 | lcode = state->lencode;
97 | dcode = state->distcode;
98 | lmask = (1U << state->lenbits) - 1;
99 | dmask = (1U << state->distbits) - 1;
100 |
101 | /* decode literals and length/distances until end-of-block or not enough
102 | input data or output space */
103 | do {
104 | if (bits < 15) {
105 | hold += (unsigned long)(*in++) << bits;
106 | bits += 8;
107 | hold += (unsigned long)(*in++) << bits;
108 | bits += 8;
109 | }
110 | here = lcode[hold & lmask];
111 | dolen:
112 | op = (unsigned)(here.bits);
113 | hold >>= op;
114 | bits -= op;
115 | op = (unsigned)(here.op);
116 | if (op == 0) { /* literal */
117 | Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
118 | "inflate: literal '%c'\n" :
119 | "inflate: literal 0x%02x\n", here.val));
120 | *out++ = (unsigned char)(here.val);
121 | }
122 | else if (op & 16) { /* length base */
123 | len = (unsigned)(here.val);
124 | op &= 15; /* number of extra bits */
125 | if (op) {
126 | if (bits < op) {
127 | hold += (unsigned long)(*in++) << bits;
128 | bits += 8;
129 | }
130 | len += (unsigned)hold & ((1U << op) - 1);
131 | hold >>= op;
132 | bits -= op;
133 | }
134 | Tracevv((stderr, "inflate: length %u\n", len));
135 | if (bits < 15) {
136 | hold += (unsigned long)(*in++) << bits;
137 | bits += 8;
138 | hold += (unsigned long)(*in++) << bits;
139 | bits += 8;
140 | }
141 | here = dcode[hold & dmask];
142 | dodist:
143 | op = (unsigned)(here.bits);
144 | hold >>= op;
145 | bits -= op;
146 | op = (unsigned)(here.op);
147 | if (op & 16) { /* distance base */
148 | dist = (unsigned)(here.val);
149 | op &= 15; /* number of extra bits */
150 | if (bits < op) {
151 | hold += (unsigned long)(*in++) << bits;
152 | bits += 8;
153 | if (bits < op) {
154 | hold += (unsigned long)(*in++) << bits;
155 | bits += 8;
156 | }
157 | }
158 | dist += (unsigned)hold & ((1U << op) - 1);
159 | #ifdef INFLATE_STRICT
160 | if (dist > dmax) {
161 | strm->msg = (char *)"invalid distance too far back";
162 | state->mode = BAD;
163 | break;
164 | }
165 | #endif
166 | hold >>= op;
167 | bits -= op;
168 | Tracevv((stderr, "inflate: distance %u\n", dist));
169 | op = (unsigned)(out - beg); /* max distance in output */
170 | if (dist > op) { /* see if copy from window */
171 | op = dist - op; /* distance back in window */
172 | if (op > whave) {
173 | if (state->sane) {
174 | strm->msg =
175 | (char *)"invalid distance too far back";
176 | state->mode = BAD;
177 | break;
178 | }
179 | #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
180 | if (len <= op - whave) {
181 | do {
182 | *out++ = 0;
183 | } while (--len);
184 | continue;
185 | }
186 | len -= op - whave;
187 | do {
188 | *out++ = 0;
189 | } while (--op > whave);
190 | if (op == 0) {
191 | from = out - dist;
192 | do {
193 | *out++ = *from++;
194 | } while (--len);
195 | continue;
196 | }
197 | #endif
198 | }
199 | from = window;
200 | if (wnext == 0) { /* very common case */
201 | from += wsize - op;
202 | if (op < len) { /* some from window */
203 | len -= op;
204 | do {
205 | *out++ = *from++;
206 | } while (--op);
207 | from = out - dist; /* rest from output */
208 | }
209 | }
210 | else if (wnext < op) { /* wrap around window */
211 | from += wsize + wnext - op;
212 | op -= wnext;
213 | if (op < len) { /* some from end of window */
214 | len -= op;
215 | do {
216 | *out++ = *from++;
217 | } while (--op);
218 | from = window;
219 | if (wnext < len) { /* some from start of window */
220 | op = wnext;
221 | len -= op;
222 | do {
223 | *out++ = *from++;
224 | } while (--op);
225 | from = out - dist; /* rest from output */
226 | }
227 | }
228 | }
229 | else { /* contiguous in window */
230 | from += wnext - op;
231 | if (op < len) { /* some from window */
232 | len -= op;
233 | do {
234 | *out++ = *from++;
235 | } while (--op);
236 | from = out - dist; /* rest from output */
237 | }
238 | }
239 | while (len > 2) {
240 | *out++ = *from++;
241 | *out++ = *from++;
242 | *out++ = *from++;
243 | len -= 3;
244 | }
245 | if (len) {
246 | *out++ = *from++;
247 | if (len > 1)
248 | *out++ = *from++;
249 | }
250 | }
251 | else {
252 | from = out - dist; /* copy direct from output */
253 | do { /* minimum length is three */
254 | *out++ = *from++;
255 | *out++ = *from++;
256 | *out++ = *from++;
257 | len -= 3;
258 | } while (len > 2);
259 | if (len) {
260 | *out++ = *from++;
261 | if (len > 1)
262 | *out++ = *from++;
263 | }
264 | }
265 | }
266 | else if ((op & 64) == 0) { /* 2nd level distance code */
267 | here = dcode[here.val + (hold & ((1U << op) - 1))];
268 | goto dodist;
269 | }
270 | else {
271 | strm->msg = (char *)"invalid distance code";
272 | state->mode = BAD;
273 | break;
274 | }
275 | }
276 | else if ((op & 64) == 0) { /* 2nd level length code */
277 | here = lcode[here.val + (hold & ((1U << op) - 1))];
278 | goto dolen;
279 | }
280 | else if (op & 32) { /* end-of-block */
281 | Tracevv((stderr, "inflate: end of block\n"));
282 | state->mode = TYPE;
283 | break;
284 | }
285 | else {
286 | strm->msg = (char *)"invalid literal/length code";
287 | state->mode = BAD;
288 | break;
289 | }
290 | } while (in < last && out < end);
291 |
292 | /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
293 | len = bits >> 3;
294 | in -= len;
295 | bits -= len << 3;
296 | hold &= (1U << bits) - 1;
297 |
298 | /* update state and return */
299 | strm->next_in = in;
300 | strm->next_out = out;
301 | strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
302 | strm->avail_out = (unsigned)(out < end ?
303 | 257 + (end - out) : 257 - (out - end));
304 | state->hold = hold;
305 | state->bits = bits;
306 | return;
307 | }
308 |
309 | /*
310 | inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
311 | - Using bit fields for code structure
312 | - Different op definition to avoid & for extra bits (do & for table bits)
313 | - Three separate decoding do-loops for direct, window, and wnext == 0
314 | - Special case for distance > 1 copies to do overlapped load and store copy
315 | - Explicit branch predictions (based on measured branch probabilities)
316 | - Deferring match copy and interspersed it with decoding subsequent codes
317 | - Swapping literal/length else
318 | - Swapping window/direct else
319 | - Larger unrolled copy loops (three is about right)
320 | - Moving len -= 3 statement into middle of loop
321 | */
322 |
323 | #endif /* !ASMINF */
324 |
--------------------------------------------------------------------------------
/zlib/inffast.h:
--------------------------------------------------------------------------------
1 | /* inffast.h -- header to use inffast.c
2 | * Copyright (C) 1995-2003, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
12 |
--------------------------------------------------------------------------------
/zlib/inffixed.h:
--------------------------------------------------------------------------------
1 | /* inffixed.h -- table for decoding fixed codes
2 | * Generated automatically by makefixed().
3 | */
4 |
5 | /* WARNING: this file should *not* be used by applications.
6 | It is part of the implementation of this library and is
7 | subject to change. Applications should only use zlib.h.
8 | */
9 |
10 | static const code lenfix[512] = {
11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
84 | {0,9,255}
85 | };
86 |
87 | static const code distfix[32] = {
88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
93 | {22,5,193},{64,5,0}
94 | };
95 |
--------------------------------------------------------------------------------
/zlib/inflate.h:
--------------------------------------------------------------------------------
1 | /* inflate.h -- internal inflate state definition
2 | * Copyright (C) 1995-2016 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* define NO_GZIP when compiling if you want to disable gzip header and
12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
13 | the crc code when it is not needed. For shared libraries, gzip decoding
14 | should be left enabled. */
15 | #ifndef NO_GZIP
16 | # define GUNZIP
17 | #endif
18 |
19 | /* Possible inflate modes between inflate() calls */
20 | typedef enum {
21 | HEAD = 16180, /* i: waiting for magic header */
22 | FLAGS, /* i: waiting for method and flags (gzip) */
23 | TIME, /* i: waiting for modification time (gzip) */
24 | OS, /* i: waiting for extra flags and operating system (gzip) */
25 | EXLEN, /* i: waiting for extra length (gzip) */
26 | EXTRA, /* i: waiting for extra bytes (gzip) */
27 | NAME, /* i: waiting for end of file name (gzip) */
28 | COMMENT, /* i: waiting for end of comment (gzip) */
29 | HCRC, /* i: waiting for header crc (gzip) */
30 | DICTID, /* i: waiting for dictionary check value */
31 | DICT, /* waiting for inflateSetDictionary() call */
32 | TYPE, /* i: waiting for type bits, including last-flag bit */
33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */
34 | STORED, /* i: waiting for stored size (length and complement) */
35 | COPY_, /* i/o: same as COPY below, but only first time in */
36 | COPY, /* i/o: waiting for input or output to copy stored block */
37 | TABLE, /* i: waiting for dynamic block table lengths */
38 | LENLENS, /* i: waiting for code length code lengths */
39 | CODELENS, /* i: waiting for length/lit and distance code lengths */
40 | LEN_, /* i: same as LEN below, but only first time in */
41 | LEN, /* i: waiting for length/lit/eob code */
42 | LENEXT, /* i: waiting for length extra bits */
43 | DIST, /* i: waiting for distance code */
44 | DISTEXT, /* i: waiting for distance extra bits */
45 | MATCH, /* o: waiting for output space to copy string */
46 | LIT, /* o: waiting for output space to write literal */
47 | CHECK, /* i: waiting for 32-bit check value */
48 | LENGTH, /* i: waiting for 32-bit length (gzip) */
49 | DONE, /* finished check, done -- remain here until reset */
50 | BAD, /* got a data error -- remain here until reset */
51 | MEM, /* got an inflate() memory error -- remain here until reset */
52 | SYNC /* looking for synchronization bytes to restart inflate() */
53 | } inflate_mode;
54 |
55 | /*
56 | State transitions between above modes -
57 |
58 | (most modes can go to BAD or MEM on error -- not shown for clarity)
59 |
60 | Process header:
61 | HEAD -> (gzip) or (zlib) or (raw)
62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
63 | HCRC -> TYPE
64 | (zlib) -> DICTID or TYPE
65 | DICTID -> DICT -> TYPE
66 | (raw) -> TYPEDO
67 | Read deflate blocks:
68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
69 | STORED -> COPY_ -> COPY -> TYPE
70 | TABLE -> LENLENS -> CODELENS -> LEN_
71 | LEN_ -> LEN
72 | Read deflate codes in fixed or dynamic block:
73 | LEN -> LENEXT or LIT or TYPE
74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
75 | LIT -> LEN
76 | Process trailer:
77 | CHECK -> LENGTH -> DONE
78 | */
79 |
80 | /* State maintained between inflate() calls -- approximately 7K bytes, not
81 | including the allocated sliding window, which is up to 32K bytes. */
82 | struct inflate_state {
83 | z_streamp strm; /* pointer back to this zlib stream */
84 | inflate_mode mode; /* current inflate mode */
85 | int last; /* true if processing last block */
86 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip,
87 | bit 2 true to validate check value */
88 | int havedict; /* true if dictionary provided */
89 | int flags; /* gzip header method and flags (0 if zlib) */
90 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
91 | unsigned long check; /* protected copy of check value */
92 | unsigned long total; /* protected copy of output count */
93 | gz_headerp head; /* where to save gzip header information */
94 | /* sliding window */
95 | unsigned wbits; /* log base 2 of requested window size */
96 | unsigned wsize; /* window size or zero if not using window */
97 | unsigned whave; /* valid bytes in the window */
98 | unsigned wnext; /* window write index */
99 | unsigned char FAR *window; /* allocated sliding window, if needed */
100 | /* bit accumulator */
101 | unsigned long hold; /* input bit accumulator */
102 | unsigned bits; /* number of bits in "in" */
103 | /* for string and stored block copying */
104 | unsigned length; /* literal or length of data to copy */
105 | unsigned offset; /* distance back to copy string from */
106 | /* for table and code decoding */
107 | unsigned extra; /* extra bits needed */
108 | /* fixed and dynamic code tables */
109 | code const FAR *lencode; /* starting table for length/literal codes */
110 | code const FAR *distcode; /* starting table for distance codes */
111 | unsigned lenbits; /* index bits for lencode */
112 | unsigned distbits; /* index bits for distcode */
113 | /* dynamic table building */
114 | unsigned ncode; /* number of code length code lengths */
115 | unsigned nlen; /* number of length code lengths */
116 | unsigned ndist; /* number of distance code lengths */
117 | unsigned have; /* number of code lengths in lens[] */
118 | code FAR *next; /* next available space in codes[] */
119 | unsigned short lens[320]; /* temporary storage for code lengths */
120 | unsigned short work[288]; /* work area for code table building */
121 | code codes[ENOUGH]; /* space for code tables */
122 | int sane; /* if false, allow invalid distance too far */
123 | int back; /* bits back of last unprocessed length/lit */
124 | unsigned was; /* initial length of match */
125 | };
126 |
--------------------------------------------------------------------------------
/zlib/inftrees.c:
--------------------------------------------------------------------------------
1 | /* inftrees.c -- generate Huffman trees for efficient decoding
2 | * Copyright (C) 1995-2017 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #include "zutil.h"
7 | #include "inftrees.h"
8 |
9 | #define MAXBITS 15
10 |
11 | const char inflate_copyright[] =
12 | " inflate 1.2.11 Copyright 1995-2017 Mark Adler ";
13 | /*
14 | If you use the zlib library in a product, an acknowledgment is welcome
15 | in the documentation of your product. If for some reason you cannot
16 | include such an acknowledgment, I would appreciate that you keep this
17 | copyright string in the executable of your product.
18 | */
19 |
20 | /*
21 | Build a set of tables to decode the provided canonical Huffman code.
22 | The code lengths are lens[0..codes-1]. The result starts at *table,
23 | whose indices are 0..2^bits-1. work is a writable array of at least
24 | lens shorts, which is used as a work area. type is the type of code
25 | to be generated, CODES, LENS, or DISTS. On return, zero is success,
26 | -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
27 | on return points to the next available entry's address. bits is the
28 | requested root table index bits, and on return it is the actual root
29 | table index bits. It will differ if the request is greater than the
30 | longest code or if it is less than the shortest code.
31 | */
32 | int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
33 | codetype type;
34 | unsigned short FAR *lens;
35 | unsigned codes;
36 | code FAR * FAR *table;
37 | unsigned FAR *bits;
38 | unsigned short FAR *work;
39 | {
40 | unsigned len; /* a code's length in bits */
41 | unsigned sym; /* index of code symbols */
42 | unsigned min, max; /* minimum and maximum code lengths */
43 | unsigned root; /* number of index bits for root table */
44 | unsigned curr; /* number of index bits for current table */
45 | unsigned drop; /* code bits to drop for sub-table */
46 | int left; /* number of prefix codes available */
47 | unsigned used; /* code entries in table used */
48 | unsigned huff; /* Huffman code */
49 | unsigned incr; /* for incrementing code, index */
50 | unsigned fill; /* index for replicating entries */
51 | unsigned low; /* low bits for current root entry */
52 | unsigned mask; /* mask for low root bits */
53 | code here; /* table entry for duplication */
54 | code FAR *next; /* next available space in table */
55 | const unsigned short FAR *base; /* base value table to use */
56 | const unsigned short FAR *extra; /* extra bits table to use */
57 | unsigned match; /* use base and extra for symbol >= match */
58 | unsigned short count[MAXBITS+1]; /* number of codes of each length */
59 | unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
60 | static const unsigned short lbase[31] = { /* Length codes 257..285 base */
61 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
62 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
63 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */
64 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
65 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202};
66 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
67 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
68 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
69 | 8193, 12289, 16385, 24577, 0, 0};
70 | static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
71 | 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
72 | 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
73 | 28, 28, 29, 29, 64, 64};
74 |
75 | /*
76 | Process a set of code lengths to create a canonical Huffman code. The
77 | code lengths are lens[0..codes-1]. Each length corresponds to the
78 | symbols 0..codes-1. The Huffman code is generated by first sorting the
79 | symbols by length from short to long, and retaining the symbol order
80 | for codes with equal lengths. Then the code starts with all zero bits
81 | for the first code of the shortest length, and the codes are integer
82 | increments for the same length, and zeros are appended as the length
83 | increases. For the deflate format, these bits are stored backwards
84 | from their more natural integer increment ordering, and so when the
85 | decoding tables are built in the large loop below, the integer codes
86 | are incremented backwards.
87 |
88 | This routine assumes, but does not check, that all of the entries in
89 | lens[] are in the range 0..MAXBITS. The caller must assure this.
90 | 1..MAXBITS is interpreted as that code length. zero means that that
91 | symbol does not occur in this code.
92 |
93 | The codes are sorted by computing a count of codes for each length,
94 | creating from that a table of starting indices for each length in the
95 | sorted table, and then entering the symbols in order in the sorted
96 | table. The sorted table is work[], with that space being provided by
97 | the caller.
98 |
99 | The length counts are used for other purposes as well, i.e. finding
100 | the minimum and maximum length codes, determining if there are any
101 | codes at all, checking for a valid set of lengths, and looking ahead
102 | at length counts to determine sub-table sizes when building the
103 | decoding tables.
104 | */
105 |
106 | /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
107 | for (len = 0; len <= MAXBITS; len++)
108 | count[len] = 0;
109 | for (sym = 0; sym < codes; sym++)
110 | count[lens[sym]]++;
111 |
112 | /* bound code lengths, force root to be within code lengths */
113 | root = *bits;
114 | for (max = MAXBITS; max >= 1; max--)
115 | if (count[max] != 0) break;
116 | if (root > max) root = max;
117 | if (max == 0) { /* no symbols to code at all */
118 | here.op = (unsigned char)64; /* invalid code marker */
119 | here.bits = (unsigned char)1;
120 | here.val = (unsigned short)0;
121 | *(*table)++ = here; /* make a table to force an error */
122 | *(*table)++ = here;
123 | *bits = 1;
124 | return 0; /* no symbols, but wait for decoding to report error */
125 | }
126 | for (min = 1; min < max; min++)
127 | if (count[min] != 0) break;
128 | if (root < min) root = min;
129 |
130 | /* check for an over-subscribed or incomplete set of lengths */
131 | left = 1;
132 | for (len = 1; len <= MAXBITS; len++) {
133 | left <<= 1;
134 | left -= count[len];
135 | if (left < 0) return -1; /* over-subscribed */
136 | }
137 | if (left > 0 && (type == CODES || max != 1))
138 | return -1; /* incomplete set */
139 |
140 | /* generate offsets into symbol table for each length for sorting */
141 | offs[1] = 0;
142 | for (len = 1; len < MAXBITS; len++)
143 | offs[len + 1] = offs[len] + count[len];
144 |
145 | /* sort symbols by length, by symbol order within each length */
146 | for (sym = 0; sym < codes; sym++)
147 | if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
148 |
149 | /*
150 | Create and fill in decoding tables. In this loop, the table being
151 | filled is at next and has curr index bits. The code being used is huff
152 | with length len. That code is converted to an index by dropping drop
153 | bits off of the bottom. For codes where len is less than drop + curr,
154 | those top drop + curr - len bits are incremented through all values to
155 | fill the table with replicated entries.
156 |
157 | root is the number of index bits for the root table. When len exceeds
158 | root, sub-tables are created pointed to by the root entry with an index
159 | of the low root bits of huff. This is saved in low to check for when a
160 | new sub-table should be started. drop is zero when the root table is
161 | being filled, and drop is root when sub-tables are being filled.
162 |
163 | When a new sub-table is needed, it is necessary to look ahead in the
164 | code lengths to determine what size sub-table is needed. The length
165 | counts are used for this, and so count[] is decremented as codes are
166 | entered in the tables.
167 |
168 | used keeps track of how many table entries have been allocated from the
169 | provided *table space. It is checked for LENS and DIST tables against
170 | the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
171 | the initial root table size constants. See the comments in inftrees.h
172 | for more information.
173 |
174 | sym increments through all symbols, and the loop terminates when
175 | all codes of length max, i.e. all codes, have been processed. This
176 | routine permits incomplete codes, so another loop after this one fills
177 | in the rest of the decoding tables with invalid code markers.
178 | */
179 |
180 | /* set up for code type */
181 | switch (type) {
182 | case CODES:
183 | base = extra = work; /* dummy value--not used */
184 | match = 20;
185 | break;
186 | case LENS:
187 | base = lbase;
188 | extra = lext;
189 | match = 257;
190 | break;
191 | default: /* DISTS */
192 | base = dbase;
193 | extra = dext;
194 | match = 0;
195 | }
196 |
197 | /* initialize state for loop */
198 | huff = 0; /* starting code */
199 | sym = 0; /* starting code symbol */
200 | len = min; /* starting code length */
201 | next = *table; /* current table to fill in */
202 | curr = root; /* current table index bits */
203 | drop = 0; /* current bits to drop from code for index */
204 | low = (unsigned)(-1); /* trigger new sub-table when len > root */
205 | used = 1U << root; /* use root table entries */
206 | mask = used - 1; /* mask for comparing low */
207 |
208 | /* check available table space */
209 | if ((type == LENS && used > ENOUGH_LENS) ||
210 | (type == DISTS && used > ENOUGH_DISTS))
211 | return 1;
212 |
213 | /* process all codes and make table entries */
214 | for (;;) {
215 | /* create table entry */
216 | here.bits = (unsigned char)(len - drop);
217 | if (work[sym] + 1U < match) {
218 | here.op = (unsigned char)0;
219 | here.val = work[sym];
220 | }
221 | else if (work[sym] >= match) {
222 | here.op = (unsigned char)(extra[work[sym] - match]);
223 | here.val = base[work[sym] - match];
224 | }
225 | else {
226 | here.op = (unsigned char)(32 + 64); /* end of block */
227 | here.val = 0;
228 | }
229 |
230 | /* replicate for those indices with low len bits equal to huff */
231 | incr = 1U << (len - drop);
232 | fill = 1U << curr;
233 | min = fill; /* save offset to next table */
234 | do {
235 | fill -= incr;
236 | next[(huff >> drop) + fill] = here;
237 | } while (fill != 0);
238 |
239 | /* backwards increment the len-bit code huff */
240 | incr = 1U << (len - 1);
241 | while (huff & incr)
242 | incr >>= 1;
243 | if (incr != 0) {
244 | huff &= incr - 1;
245 | huff += incr;
246 | }
247 | else
248 | huff = 0;
249 |
250 | /* go to next symbol, update count, len */
251 | sym++;
252 | if (--(count[len]) == 0) {
253 | if (len == max) break;
254 | len = lens[work[sym]];
255 | }
256 |
257 | /* create new sub-table if needed */
258 | if (len > root && (huff & mask) != low) {
259 | /* if first time, transition to sub-tables */
260 | if (drop == 0)
261 | drop = root;
262 |
263 | /* increment past last table */
264 | next += min; /* here min is 1 << curr */
265 |
266 | /* determine length of next table */
267 | curr = len - drop;
268 | left = (int)(1 << curr);
269 | while (curr + drop < max) {
270 | left -= count[curr + drop];
271 | if (left <= 0) break;
272 | curr++;
273 | left <<= 1;
274 | }
275 |
276 | /* check for enough space */
277 | used += 1U << curr;
278 | if ((type == LENS && used > ENOUGH_LENS) ||
279 | (type == DISTS && used > ENOUGH_DISTS))
280 | return 1;
281 |
282 | /* point entry in root table to sub-table */
283 | low = huff & mask;
284 | (*table)[low].op = (unsigned char)curr;
285 | (*table)[low].bits = (unsigned char)root;
286 | (*table)[low].val = (unsigned short)(next - *table);
287 | }
288 | }
289 |
290 | /* fill in remaining table entry if code is incomplete (guaranteed to have
291 | at most one remaining entry, since if the code is incomplete, the
292 | maximum code length that was allowed to get this far is one bit) */
293 | if (huff != 0) {
294 | here.op = (unsigned char)64; /* invalid code marker */
295 | here.bits = (unsigned char)(len - drop);
296 | here.val = (unsigned short)0;
297 | next[huff] = here;
298 | }
299 |
300 | /* set return parameters */
301 | *table += used;
302 | *bits = root;
303 | return 0;
304 | }
305 |
--------------------------------------------------------------------------------
/zlib/inftrees.h:
--------------------------------------------------------------------------------
1 | /* inftrees.h -- header to use inftrees.c
2 | * Copyright (C) 1995-2005, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* Structure for decoding tables. Each entry provides either the
12 | information needed to do the operation requested by the code that
13 | indexed that table entry, or it provides a pointer to another
14 | table that indexes more bits of the code. op indicates whether
15 | the entry is a pointer to another table, a literal, a length or
16 | distance, an end-of-block, or an invalid code. For a table
17 | pointer, the low four bits of op is the number of index bits of
18 | that table. For a length or distance, the low four bits of op
19 | is the number of extra bits to get after the code. bits is
20 | the number of bits in this code or part of the code to drop off
21 | of the bit buffer. val is the actual byte to output in the case
22 | of a literal, the base length or distance, or the offset from
23 | the current table to the next table. Each entry is four bytes. */
24 | typedef struct {
25 | unsigned char op; /* operation, extra bits, table bits */
26 | unsigned char bits; /* bits in this part of the code */
27 | unsigned short val; /* offset in table or code value */
28 | } code;
29 |
30 | /* op values as set by inflate_table():
31 | 00000000 - literal
32 | 0000tttt - table link, tttt != 0 is the number of table index bits
33 | 0001eeee - length or distance, eeee is the number of extra bits
34 | 01100000 - end of block
35 | 01000000 - invalid code
36 | */
37 |
38 | /* Maximum size of the dynamic table. The maximum number of code structures is
39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance
40 | codes. These values were found by exhaustive searches using the program
41 | examples/enough.c found in the zlib distribtution. The arguments to that
42 | program are the number of symbols, the initial root table size, and the
43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes
44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45 | The initial root table size (9 or 6) is found in the fifth argument of the
46 | inflate_table() calls in inflate.c and infback.c. If the root table size is
47 | changed, then these maximum sizes would be need to be recalculated and
48 | updated. */
49 | #define ENOUGH_LENS 852
50 | #define ENOUGH_DISTS 592
51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52 |
53 | /* Type of code to build for inflate_table() */
54 | typedef enum {
55 | CODES,
56 | LENS,
57 | DISTS
58 | } codetype;
59 |
60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61 | unsigned codes, code FAR * FAR *table,
62 | unsigned FAR *bits, unsigned short FAR *work));
63 |
--------------------------------------------------------------------------------
/zlib/treebuild.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | zip compression library
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
117 |
--------------------------------------------------------------------------------
/zlib/trees.h:
--------------------------------------------------------------------------------
1 | /* header created automatically with -DGEN_TREES_H */
2 |
3 | local const ct_data static_ltree[L_CODES+2] = {
4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
62 | };
63 |
64 | local const ct_data static_dtree[D_CODES] = {
65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
71 | };
72 |
73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {
74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
100 | };
101 |
102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {
103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
116 | };
117 |
118 | local const int base_length[LENGTH_CODES] = {
119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
120 | 64, 80, 96, 112, 128, 160, 192, 224, 0
121 | };
122 |
123 | local const int base_dist[D_CODES] = {
124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
127 | };
128 |
129 |
--------------------------------------------------------------------------------
/zlib/uncompr.c:
--------------------------------------------------------------------------------
1 | /* uncompr.c -- decompress a memory buffer
2 | * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #define ZLIB_INTERNAL
9 | #include "zlib.h"
10 |
11 | /* ===========================================================================
12 | Decompresses the source buffer into the destination buffer. *sourceLen is
13 | the byte length of the source buffer. Upon entry, *destLen is the total size
14 | of the destination buffer, which must be large enough to hold the entire
15 | uncompressed data. (The size of the uncompressed data must have been saved
16 | previously by the compressor and transmitted to the decompressor by some
17 | mechanism outside the scope of this compression library.) Upon exit,
18 | *destLen is the size of the decompressed data and *sourceLen is the number
19 | of source bytes consumed. Upon return, source + *sourceLen points to the
20 | first unused input byte.
21 |
22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
23 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
24 | Z_DATA_ERROR if the input data was corrupted, including if the input data is
25 | an incomplete zlib stream.
26 | */
27 | int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
28 | Bytef *dest;
29 | uLongf *destLen;
30 | const Bytef *source;
31 | uLong *sourceLen;
32 | {
33 | z_stream stream;
34 | int err;
35 | const uInt max = (uInt)-1;
36 | uLong len, left;
37 | Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
38 |
39 | len = *sourceLen;
40 | if (*destLen) {
41 | left = *destLen;
42 | *destLen = 0;
43 | }
44 | else {
45 | left = 1;
46 | dest = buf;
47 | }
48 |
49 | stream.next_in = (z_const Bytef *)source;
50 | stream.avail_in = 0;
51 | stream.zalloc = (alloc_func)0;
52 | stream.zfree = (free_func)0;
53 | stream.opaque = (voidpf)0;
54 |
55 | err = inflateInit(&stream);
56 | if (err != Z_OK) return err;
57 |
58 | stream.next_out = dest;
59 | stream.avail_out = 0;
60 |
61 | do {
62 | if (stream.avail_out == 0) {
63 | stream.avail_out = left > (uLong)max ? max : (uInt)left;
64 | left -= stream.avail_out;
65 | }
66 | if (stream.avail_in == 0) {
67 | stream.avail_in = len > (uLong)max ? max : (uInt)len;
68 | len -= stream.avail_in;
69 | }
70 | err = inflate(&stream, Z_NO_FLUSH);
71 | } while (err == Z_OK);
72 |
73 | *sourceLen -= len + stream.avail_in;
74 | if (dest != buf)
75 | *destLen = stream.total_out;
76 | else if (stream.total_out && err == Z_BUF_ERROR)
77 | left = 1;
78 |
79 | inflateEnd(&stream);
80 | return err == Z_STREAM_END ? Z_OK :
81 | err == Z_NEED_DICT ? Z_DATA_ERROR :
82 | err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
83 | err;
84 | }
85 |
86 | int ZEXPORT uncompress (dest, destLen, source, sourceLen)
87 | Bytef *dest;
88 | uLongf *destLen;
89 | const Bytef *source;
90 | uLong sourceLen;
91 | {
92 | return uncompress2(dest, destLen, source, &sourceLen);
93 | }
94 |
--------------------------------------------------------------------------------
/zlib/zlib.3:
--------------------------------------------------------------------------------
1 | .TH ZLIB 3 "15 Jan 2017"
2 | .SH NAME
3 | zlib \- compression/decompression library
4 | .SH SYNOPSIS
5 | [see
6 | .I zlib.h
7 | for full description]
8 | .SH DESCRIPTION
9 | The
10 | .I zlib
11 | library is a general purpose data compression library.
12 | The code is thread safe, assuming that the standard library functions
13 | used are thread safe, such as memory allocation routines.
14 | It provides in-memory compression and decompression functions,
15 | including integrity checks of the uncompressed data.
16 | This version of the library supports only one compression method (deflation)
17 | but other algorithms may be added later
18 | with the same stream interface.
19 | .LP
20 | Compression can be done in a single step if the buffers are large enough
21 | or can be done by repeated calls of the compression function.
22 | In the latter case,
23 | the application must provide more input and/or consume the output
24 | (providing more output space) before each call.
25 | .LP
26 | The library also supports reading and writing files in
27 | .IR gzip (1)
28 | (.gz) format
29 | with an interface similar to that of stdio.
30 | .LP
31 | The library does not install any signal handler.
32 | The decoder checks the consistency of the compressed data,
33 | so the library should never crash even in the case of corrupted input.
34 | .LP
35 | All functions of the compression library are documented in the file
36 | .IR zlib.h .
37 | The distribution source includes examples of use of the library
38 | in the files
39 | .I test/example.c
40 | and
41 | .IR test/minigzip.c,
42 | as well as other examples in the
43 | .IR examples/
44 | directory.
45 | .LP
46 | Changes to this version are documented in the file
47 | .I ChangeLog
48 | that accompanies the source.
49 | .LP
50 | .I zlib
51 | is built in to many languages and operating systems, including but not limited to
52 | Java, Python, .NET, PHP, Perl, Ruby, Swift, and Go.
53 | .LP
54 | An experimental package to read and write files in the .zip format,
55 | written on top of
56 | .I zlib
57 | by Gilles Vollant (info@winimage.com),
58 | is available at:
59 | .IP
60 | http://www.winimage.com/zLibDll/minizip.html
61 | and also in the
62 | .I contrib/minizip
63 | directory of the main
64 | .I zlib
65 | source distribution.
66 | .SH "SEE ALSO"
67 | The
68 | .I zlib
69 | web site can be found at:
70 | .IP
71 | http://zlib.net/
72 | .LP
73 | The data format used by the
74 | .I zlib
75 | library is described by RFC
76 | (Request for Comments) 1950 to 1952 in the files:
77 | .IP
78 | http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format)
79 | .br
80 | http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format)
81 | .br
82 | http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format)
83 | .LP
84 | Mark Nelson wrote an article about
85 | .I zlib
86 | for the Jan. 1997 issue of Dr. Dobb's Journal;
87 | a copy of the article is available at:
88 | .IP
89 | http://marknelson.us/1997/01/01/zlib-engine/
90 | .SH "REPORTING PROBLEMS"
91 | Before reporting a problem,
92 | please check the
93 | .I zlib
94 | web site to verify that you have the latest version of
95 | .IR zlib ;
96 | otherwise,
97 | obtain the latest version and see if the problem still exists.
98 | Please read the
99 | .I zlib
100 | FAQ at:
101 | .IP
102 | http://zlib.net/zlib_faq.html
103 | .LP
104 | before asking for help.
105 | Send questions and/or comments to zlib@gzip.org,
106 | or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
107 | .SH AUTHORS AND LICENSE
108 | Version 1.2.11
109 | .LP
110 | Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
111 | .LP
112 | This software is provided 'as-is', without any express or implied
113 | warranty. In no event will the authors be held liable for any damages
114 | arising from the use of this software.
115 | .LP
116 | Permission is granted to anyone to use this software for any purpose,
117 | including commercial applications, and to alter it and redistribute it
118 | freely, subject to the following restrictions:
119 | .LP
120 | .nr step 1 1
121 | .IP \n[step]. 3
122 | The origin of this software must not be misrepresented; you must not
123 | claim that you wrote the original software. If you use this software
124 | in a product, an acknowledgment in the product documentation would be
125 | appreciated but is not required.
126 | .IP \n+[step].
127 | Altered source versions must be plainly marked as such, and must not be
128 | misrepresented as being the original software.
129 | .IP \n+[step].
130 | This notice may not be removed or altered from any source distribution.
131 | .LP
132 | Jean-loup Gailly Mark Adler
133 | .br
134 | jloup@gzip.org madler@alumni.caltech.edu
135 | .LP
136 | The deflate format used by
137 | .I zlib
138 | was defined by Phil Katz.
139 | The deflate and
140 | .I zlib
141 | specifications were written by L. Peter Deutsch.
142 | Thanks to all the people who reported problems and suggested various
143 | improvements in
144 | .IR zlib ;
145 | who are too numerous to cite here.
146 | .LP
147 | UNIX manual page by R. P. C. Rodgers,
148 | U.S. National Library of Medicine (rodgers@nlm.nih.gov).
149 | .\" end of man page
150 |
--------------------------------------------------------------------------------
/zlib/zlib.3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mcollina/native-hdr-histogram/5569e65d0f5f56a7ea432a2e985aec7cf8aaaeaf/zlib/zlib.3.pdf
--------------------------------------------------------------------------------
/zlib/zlib.gyp:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 | # Use of this source code is governed by a BSD-style license that can be
3 | # found in the LICENSE file.
4 |
5 | {
6 | 'variables': {
7 | 'use_system_zlib%': 0
8 | },
9 | 'conditions': [
10 | ['use_system_zlib==0', {
11 | 'targets': [
12 | {
13 | 'target_name': 'zlib',
14 | 'type': 'static_library',
15 | 'sources': [
16 | 'adler32.c',
17 | 'compress.c',
18 | 'crc32.c',
19 | 'crc32.h',
20 | 'deflate.c',
21 | 'deflate.h',
22 | 'gzclose.c',
23 | 'gzguts.h',
24 | 'gzlib.c',
25 | 'gzread.c',
26 | 'gzwrite.c',
27 | 'infback.c',
28 | 'inffast.c',
29 | 'inffast.h',
30 | 'inffixed.h',
31 | 'inflate.c',
32 | 'inflate.h',
33 | 'inftrees.c',
34 | 'inftrees.h',
35 | 'trees.c',
36 | 'trees.h',
37 | 'uncompr.c',
38 | 'zconf.h',
39 | 'zlib.h',
40 | 'zutil.c',
41 | 'zutil.h',
42 | ],
43 | 'include_dirs': [
44 | '.',
45 | ],
46 | 'direct_dependent_settings': {
47 | 'include_dirs': [
48 | '.',
49 | ],
50 | },
51 | 'conditions': [
52 | ['OS!="win"', {
53 | 'cflags!': [ '-ansi' ],
54 | 'defines': [ 'Z_HAVE_UNISTD_H' ],
55 | }],
56 | ['OS=="mac" or OS=="ios" or OS=="freebsd" or OS=="android"', {
57 | # Mac, Android and the BSDs don't have fopen64, ftello64, or
58 | # fseeko64. We use fopen, ftell, and fseek instead on these
59 | # systems.
60 | 'defines': [
61 | 'USE_FILE32API'
62 | ],
63 | }],
64 | ],
65 | },
66 | ],
67 | }, {
68 | 'targets': [
69 | {
70 | 'target_name': 'zlib',
71 | 'type': 'static_library',
72 | 'direct_dependent_settings': {
73 | 'defines': [
74 | 'USE_SYSTEM_ZLIB',
75 | ],
76 | },
77 | 'defines': [
78 | 'USE_SYSTEM_ZLIB',
79 | ],
80 | 'link_settings': {
81 | 'libraries': [
82 | '-lz',
83 | ],
84 | },
85 | },
86 | ],
87 | }],
88 | ],
89 | }
90 |
--------------------------------------------------------------------------------
/zlib/zlib.map:
--------------------------------------------------------------------------------
1 | ZLIB_1.2.0 {
2 | global:
3 | compressBound;
4 | deflateBound;
5 | inflateBack;
6 | inflateBackEnd;
7 | inflateBackInit_;
8 | inflateCopy;
9 | local:
10 | deflate_copyright;
11 | inflate_copyright;
12 | inflate_fast;
13 | inflate_table;
14 | zcalloc;
15 | zcfree;
16 | z_errmsg;
17 | gz_error;
18 | gz_intmax;
19 | _*;
20 | };
21 |
22 | ZLIB_1.2.0.2 {
23 | gzclearerr;
24 | gzungetc;
25 | zlibCompileFlags;
26 | } ZLIB_1.2.0;
27 |
28 | ZLIB_1.2.0.8 {
29 | deflatePrime;
30 | } ZLIB_1.2.0.2;
31 |
32 | ZLIB_1.2.2 {
33 | adler32_combine;
34 | crc32_combine;
35 | deflateSetHeader;
36 | inflateGetHeader;
37 | } ZLIB_1.2.0.8;
38 |
39 | ZLIB_1.2.2.3 {
40 | deflateTune;
41 | gzdirect;
42 | } ZLIB_1.2.2;
43 |
44 | ZLIB_1.2.2.4 {
45 | inflatePrime;
46 | } ZLIB_1.2.2.3;
47 |
48 | ZLIB_1.2.3.3 {
49 | adler32_combine64;
50 | crc32_combine64;
51 | gzopen64;
52 | gzseek64;
53 | gztell64;
54 | inflateUndermine;
55 | } ZLIB_1.2.2.4;
56 |
57 | ZLIB_1.2.3.4 {
58 | inflateReset2;
59 | inflateMark;
60 | } ZLIB_1.2.3.3;
61 |
62 | ZLIB_1.2.3.5 {
63 | gzbuffer;
64 | gzoffset;
65 | gzoffset64;
66 | gzclose_r;
67 | gzclose_w;
68 | } ZLIB_1.2.3.4;
69 |
70 | ZLIB_1.2.5.1 {
71 | deflatePending;
72 | } ZLIB_1.2.3.5;
73 |
74 | ZLIB_1.2.5.2 {
75 | deflateResetKeep;
76 | gzgetc_;
77 | inflateResetKeep;
78 | } ZLIB_1.2.5.1;
79 |
80 | ZLIB_1.2.7.1 {
81 | inflateGetDictionary;
82 | gzvprintf;
83 | } ZLIB_1.2.5.2;
84 |
85 | ZLIB_1.2.9 {
86 | inflateCodesUsed;
87 | inflateValidate;
88 | uncompress2;
89 | gzfread;
90 | gzfwrite;
91 | deflateGetDictionary;
92 | adler32_z;
93 | crc32_z;
94 | } ZLIB_1.2.7.1;
95 |
--------------------------------------------------------------------------------
/zlib/zlib.pc.cmakein:
--------------------------------------------------------------------------------
1 | prefix=@CMAKE_INSTALL_PREFIX@
2 | exec_prefix=@CMAKE_INSTALL_PREFIX@
3 | libdir=@INSTALL_LIB_DIR@
4 | sharedlibdir=@INSTALL_LIB_DIR@
5 | includedir=@INSTALL_INC_DIR@
6 |
7 | Name: zlib
8 | Description: zlib compression library
9 | Version: @VERSION@
10 |
11 | Requires:
12 | Libs: -L${libdir} -L${sharedlibdir} -lz
13 | Cflags: -I${includedir}
14 |
--------------------------------------------------------------------------------
/zlib/zlib.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | sharedlibdir=@sharedlibdir@
5 | includedir=@includedir@
6 |
7 | Name: zlib
8 | Description: zlib compression library
9 | Version: @VERSION@
10 |
11 | Requires:
12 | Libs: -L${libdir} -L${sharedlibdir} -lz
13 | Cflags: -I${includedir}
14 |
--------------------------------------------------------------------------------
/zlib/zlib2ansi:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | # Transform K&R C function definitions into ANSI equivalent.
4 | #
5 | # Author: Paul Marquess
6 | # Version: 1.0
7 | # Date: 3 October 2006
8 |
9 | # TODO
10 | #
11 | # Asumes no function pointer parameters. unless they are typedefed.
12 | # Assumes no literal strings that look like function definitions
13 | # Assumes functions start at the beginning of a line
14 |
15 | use strict;
16 | use warnings;
17 |
18 | local $/;
19 | $_ = <>;
20 |
21 | my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments
22 |
23 | my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ;
24 | my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ;
25 | my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ;
26 |
27 |
28 | while (s/^
29 | ( # Start $1
30 | ( # Start $2
31 | .*? # Minimal eat content
32 | ( ^ \w [\w\s\*]+ ) # $3 -- function name
33 | \s* # optional whitespace
34 | ) # $2 - Matched up to before parameter list
35 |
36 | \( \s* # Literal "(" + optional whitespace
37 | ( [^\)]+ ) # $4 - one or more anythings except ")"
38 | \s* \) # optional whitespace surrounding a Literal ")"
39 |
40 | ( (?: $dList )+ ) # $5
41 |
42 | $sp ^ { # literal "{" at start of line
43 | ) # Remember to $1
44 | //xsom
45 | )
46 | {
47 | my $all = $1 ;
48 | my $prefix = $2;
49 | my $param_list = $4 ;
50 | my $params = $5;
51 |
52 | StripComments($params);
53 | StripComments($param_list);
54 | $param_list =~ s/^\s+//;
55 | $param_list =~ s/\s+$//;
56 |
57 | my $i = 0 ;
58 | my %pList = map { $_ => $i++ }
59 | split /\s*,\s*/, $param_list;
60 | my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ;
61 |
62 | my @params = split /\s*;\s*/, $params;
63 | my @outParams = ();
64 | foreach my $p (@params)
65 | {
66 | if ($p =~ /,/)
67 | {
68 | my @bits = split /\s*,\s*/, $p;
69 | my $first = shift @bits;
70 | $first =~ s/^\s*//;
71 | push @outParams, $first;
72 | $first =~ /^(\w+\s*)/;
73 | my $type = $1 ;
74 | push @outParams, map { $type . $_ } @bits;
75 | }
76 | else
77 | {
78 | $p =~ s/^\s+//;
79 | push @outParams, $p;
80 | }
81 | }
82 |
83 |
84 | my %tmp = map { /$pMatch/; $_ => $pList{$1} }
85 | @outParams ;
86 |
87 | @outParams = map { " $_" }
88 | sort { $tmp{$a} <=> $tmp{$b} }
89 | @outParams ;
90 |
91 | print $prefix ;
92 | print "(\n" . join(",\n", @outParams) . ")\n";
93 | print "{" ;
94 |
95 | }
96 |
97 | # Output any trailing code.
98 | print ;
99 | exit 0;
100 |
101 |
102 | sub StripComments
103 | {
104 |
105 | no warnings;
106 |
107 | # Strip C & C++ coments
108 | # From the perlfaq
109 | $_[0] =~
110 |
111 | s{
112 | /\* ## Start of /* ... */ comment
113 | [^*]*\*+ ## Non-* followed by 1-or-more *'s
114 | (
115 | [^/*][^*]*\*+
116 | )* ## 0-or-more things which don't start with /
117 | ## but do end with '*'
118 | / ## End of /* ... */ comment
119 |
120 | | ## OR C++ Comment
121 | // ## Start of C++ comment //
122 | [^\n]* ## followed by 0-or-more non end of line characters
123 |
124 | | ## OR various things which aren't comments:
125 |
126 | (
127 | " ## Start of " ... " string
128 | (
129 | \\. ## Escaped char
130 | | ## OR
131 | [^"\\] ## Non "\
132 | )*
133 | " ## End of " ... " string
134 |
135 | | ## OR
136 |
137 | ' ## Start of ' ... ' string
138 | (
139 | \\. ## Escaped char
140 | | ## OR
141 | [^'\\] ## Non '\
142 | )*
143 | ' ## End of ' ... ' string
144 |
145 | | ## OR
146 |
147 | . ## Anything other char
148 | [^/"'\\]* ## Chars which doesn't start a comment, string or escape
149 | )
150 | }{$2}gxs;
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/zlib/zutil.c:
--------------------------------------------------------------------------------
1 | /* zutil.c -- target dependent utility functions for the compression library
2 | * Copyright (C) 1995-2017 Jean-loup Gailly
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #include "zutil.h"
9 | #ifndef Z_SOLO
10 | # include "gzguts.h"
11 | #endif
12 |
13 | z_const char * const z_errmsg[10] = {
14 | (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
15 | (z_const char *)"stream end", /* Z_STREAM_END 1 */
16 | (z_const char *)"", /* Z_OK 0 */
17 | (z_const char *)"file error", /* Z_ERRNO (-1) */
18 | (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
19 | (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
20 | (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
21 | (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
22 | (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
23 | (z_const char *)""
24 | };
25 |
26 |
27 | const char * ZEXPORT zlibVersion()
28 | {
29 | return ZLIB_VERSION;
30 | }
31 |
32 | uLong ZEXPORT zlibCompileFlags()
33 | {
34 | uLong flags;
35 |
36 | flags = 0;
37 | switch ((int)(sizeof(uInt))) {
38 | case 2: break;
39 | case 4: flags += 1; break;
40 | case 8: flags += 2; break;
41 | default: flags += 3;
42 | }
43 | switch ((int)(sizeof(uLong))) {
44 | case 2: break;
45 | case 4: flags += 1 << 2; break;
46 | case 8: flags += 2 << 2; break;
47 | default: flags += 3 << 2;
48 | }
49 | switch ((int)(sizeof(voidpf))) {
50 | case 2: break;
51 | case 4: flags += 1 << 4; break;
52 | case 8: flags += 2 << 4; break;
53 | default: flags += 3 << 4;
54 | }
55 | switch ((int)(sizeof(z_off_t))) {
56 | case 2: break;
57 | case 4: flags += 1 << 6; break;
58 | case 8: flags += 2 << 6; break;
59 | default: flags += 3 << 6;
60 | }
61 | #ifdef ZLIB_DEBUG
62 | flags += 1 << 8;
63 | #endif
64 | #if defined(ASMV) || defined(ASMINF)
65 | flags += 1 << 9;
66 | #endif
67 | #ifdef ZLIB_WINAPI
68 | flags += 1 << 10;
69 | #endif
70 | #ifdef BUILDFIXED
71 | flags += 1 << 12;
72 | #endif
73 | #ifdef DYNAMIC_CRC_TABLE
74 | flags += 1 << 13;
75 | #endif
76 | #ifdef NO_GZCOMPRESS
77 | flags += 1L << 16;
78 | #endif
79 | #ifdef NO_GZIP
80 | flags += 1L << 17;
81 | #endif
82 | #ifdef PKZIP_BUG_WORKAROUND
83 | flags += 1L << 20;
84 | #endif
85 | #ifdef FASTEST
86 | flags += 1L << 21;
87 | #endif
88 | #if defined(STDC) || defined(Z_HAVE_STDARG_H)
89 | # ifdef NO_vsnprintf
90 | flags += 1L << 25;
91 | # ifdef HAS_vsprintf_void
92 | flags += 1L << 26;
93 | # endif
94 | # else
95 | # ifdef HAS_vsnprintf_void
96 | flags += 1L << 26;
97 | # endif
98 | # endif
99 | #else
100 | flags += 1L << 24;
101 | # ifdef NO_snprintf
102 | flags += 1L << 25;
103 | # ifdef HAS_sprintf_void
104 | flags += 1L << 26;
105 | # endif
106 | # else
107 | # ifdef HAS_snprintf_void
108 | flags += 1L << 26;
109 | # endif
110 | # endif
111 | #endif
112 | return flags;
113 | }
114 |
115 | #ifdef ZLIB_DEBUG
116 | #include
117 | # ifndef verbose
118 | # define verbose 0
119 | # endif
120 | int ZLIB_INTERNAL z_verbose = verbose;
121 |
122 | void ZLIB_INTERNAL z_error (m)
123 | char *m;
124 | {
125 | fprintf(stderr, "%s\n", m);
126 | exit(1);
127 | }
128 | #endif
129 |
130 | /* exported to allow conversion of error code to string for compress() and
131 | * uncompress()
132 | */
133 | const char * ZEXPORT zError(err)
134 | int err;
135 | {
136 | return ERR_MSG(err);
137 | }
138 |
139 | #if defined(_WIN32_WCE)
140 | /* The Microsoft C Run-Time Library for Windows CE doesn't have
141 | * errno. We define it as a global variable to simplify porting.
142 | * Its value is always 0 and should not be used.
143 | */
144 | int errno = 0;
145 | #endif
146 |
147 | #ifndef HAVE_MEMCPY
148 |
149 | void ZLIB_INTERNAL zmemcpy(dest, source, len)
150 | Bytef* dest;
151 | const Bytef* source;
152 | uInt len;
153 | {
154 | if (len == 0) return;
155 | do {
156 | *dest++ = *source++; /* ??? to be unrolled */
157 | } while (--len != 0);
158 | }
159 |
160 | int ZLIB_INTERNAL zmemcmp(s1, s2, len)
161 | const Bytef* s1;
162 | const Bytef* s2;
163 | uInt len;
164 | {
165 | uInt j;
166 |
167 | for (j = 0; j < len; j++) {
168 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169 | }
170 | return 0;
171 | }
172 |
173 | void ZLIB_INTERNAL zmemzero(dest, len)
174 | Bytef* dest;
175 | uInt len;
176 | {
177 | if (len == 0) return;
178 | do {
179 | *dest++ = 0; /* ??? to be unrolled */
180 | } while (--len != 0);
181 | }
182 | #endif
183 |
184 | #ifndef Z_SOLO
185 |
186 | #ifdef SYS16BIT
187 |
188 | #ifdef __TURBOC__
189 | /* Turbo C in 16-bit mode */
190 |
191 | # define MY_ZCALLOC
192 |
193 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
194 | * and farmalloc(64K) returns a pointer with an offset of 8, so we
195 | * must fix the pointer. Warning: the pointer must be put back to its
196 | * original form in order to free it, use zcfree().
197 | */
198 |
199 | #define MAX_PTR 10
200 | /* 10*64K = 640K */
201 |
202 | local int next_ptr = 0;
203 |
204 | typedef struct ptr_table_s {
205 | voidpf org_ptr;
206 | voidpf new_ptr;
207 | } ptr_table;
208 |
209 | local ptr_table table[MAX_PTR];
210 | /* This table is used to remember the original form of pointers
211 | * to large buffers (64K). Such pointers are normalized with a zero offset.
212 | * Since MSDOS is not a preemptive multitasking OS, this table is not
213 | * protected from concurrent access. This hack doesn't work anyway on
214 | * a protected system like OS/2. Use Microsoft C instead.
215 | */
216 |
217 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
218 | {
219 | voidpf buf;
220 | ulg bsize = (ulg)items*size;
221 |
222 | (void)opaque;
223 |
224 | /* If we allocate less than 65520 bytes, we assume that farmalloc
225 | * will return a usable pointer which doesn't have to be normalized.
226 | */
227 | if (bsize < 65520L) {
228 | buf = farmalloc(bsize);
229 | if (*(ush*)&buf != 0) return buf;
230 | } else {
231 | buf = farmalloc(bsize + 16L);
232 | }
233 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
234 | table[next_ptr].org_ptr = buf;
235 |
236 | /* Normalize the pointer to seg:0 */
237 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
238 | *(ush*)&buf = 0;
239 | table[next_ptr++].new_ptr = buf;
240 | return buf;
241 | }
242 |
243 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
244 | {
245 | int n;
246 |
247 | (void)opaque;
248 |
249 | if (*(ush*)&ptr != 0) { /* object < 64K */
250 | farfree(ptr);
251 | return;
252 | }
253 | /* Find the original pointer */
254 | for (n = 0; n < next_ptr; n++) {
255 | if (ptr != table[n].new_ptr) continue;
256 |
257 | farfree(table[n].org_ptr);
258 | while (++n < next_ptr) {
259 | table[n-1] = table[n];
260 | }
261 | next_ptr--;
262 | return;
263 | }
264 | Assert(0, "zcfree: ptr not found");
265 | }
266 |
267 | #endif /* __TURBOC__ */
268 |
269 |
270 | #ifdef M_I86
271 | /* Microsoft C in 16-bit mode */
272 |
273 | # define MY_ZCALLOC
274 |
275 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
276 | # define _halloc halloc
277 | # define _hfree hfree
278 | #endif
279 |
280 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
281 | {
282 | (void)opaque;
283 | return _halloc((long)items, size);
284 | }
285 |
286 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
287 | {
288 | (void)opaque;
289 | _hfree(ptr);
290 | }
291 |
292 | #endif /* M_I86 */
293 |
294 | #endif /* SYS16BIT */
295 |
296 |
297 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */
298 |
299 | #ifndef STDC
300 | extern voidp malloc OF((uInt size));
301 | extern voidp calloc OF((uInt items, uInt size));
302 | extern void free OF((voidpf ptr));
303 | #endif
304 |
305 | voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
306 | voidpf opaque;
307 | unsigned items;
308 | unsigned size;
309 | {
310 | (void)opaque;
311 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
312 | (voidpf)calloc(items, size);
313 | }
314 |
315 | void ZLIB_INTERNAL zcfree (opaque, ptr)
316 | voidpf opaque;
317 | voidpf ptr;
318 | {
319 | (void)opaque;
320 | free(ptr);
321 | }
322 |
323 | #endif /* MY_ZCALLOC */
324 |
325 | #endif /* !Z_SOLO */
326 |
--------------------------------------------------------------------------------
/zlib/zutil.h:
--------------------------------------------------------------------------------
1 | /* zutil.h -- internal interface and configuration of the compression library
2 | * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* @(#) $Id$ */
12 |
13 | #ifndef ZUTIL_H
14 | #define ZUTIL_H
15 |
16 | #ifdef HAVE_HIDDEN
17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
18 | #else
19 | # define ZLIB_INTERNAL
20 | #endif
21 |
22 | #include "zlib.h"
23 |
24 | #if defined(STDC) && !defined(Z_SOLO)
25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
26 | # include
27 | # endif
28 | # include
29 | # include
30 | #endif
31 |
32 | #ifdef Z_SOLO
33 | typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */
34 | #endif
35 |
36 | #ifndef local
37 | # define local static
38 | #endif
39 | /* since "static" is used to mean two completely different things in C, we
40 | define "local" for the non-static meaning of "static", for readability
41 | (compile with -Dlocal if your debugger can't find static symbols) */
42 |
43 | typedef unsigned char uch;
44 | typedef uch FAR uchf;
45 | typedef unsigned short ush;
46 | typedef ush FAR ushf;
47 | typedef unsigned long ulg;
48 |
49 | extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
50 | /* (size given to avoid silly warnings with Visual C++) */
51 |
52 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
53 |
54 | #define ERR_RETURN(strm,err) \
55 | return (strm->msg = ERR_MSG(err), (err))
56 | /* To be used only when the state is known to be valid */
57 |
58 | /* common constants */
59 |
60 | #ifndef DEF_WBITS
61 | # define DEF_WBITS MAX_WBITS
62 | #endif
63 | /* default windowBits for decompression. MAX_WBITS is for compression only */
64 |
65 | #if MAX_MEM_LEVEL >= 8
66 | # define DEF_MEM_LEVEL 8
67 | #else
68 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL
69 | #endif
70 | /* default memLevel */
71 |
72 | #define STORED_BLOCK 0
73 | #define STATIC_TREES 1
74 | #define DYN_TREES 2
75 | /* The three kinds of block type */
76 |
77 | #define MIN_MATCH 3
78 | #define MAX_MATCH 258
79 | /* The minimum and maximum match lengths */
80 |
81 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
82 |
83 | /* target dependencies */
84 |
85 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
86 | # define OS_CODE 0x00
87 | # ifndef Z_SOLO
88 | # if defined(__TURBOC__) || defined(__BORLANDC__)
89 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
90 | /* Allow compilation with ANSI keywords only enabled */
91 | void _Cdecl farfree( void *block );
92 | void *_Cdecl farmalloc( unsigned long nbytes );
93 | # else
94 | # include
95 | # endif
96 | # else /* MSC or DJGPP */
97 | # include
98 | # endif
99 | # endif
100 | #endif
101 |
102 | #ifdef AMIGA
103 | # define OS_CODE 1
104 | #endif
105 |
106 | #if defined(VAXC) || defined(VMS)
107 | # define OS_CODE 2
108 | # define F_OPEN(name, mode) \
109 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
110 | #endif
111 |
112 | #ifdef __370__
113 | # if __TARGET_LIB__ < 0x20000000
114 | # define OS_CODE 4
115 | # elif __TARGET_LIB__ < 0x40000000
116 | # define OS_CODE 11
117 | # else
118 | # define OS_CODE 8
119 | # endif
120 | #endif
121 |
122 | #if defined(ATARI) || defined(atarist)
123 | # define OS_CODE 5
124 | #endif
125 |
126 | #ifdef OS2
127 | # define OS_CODE 6
128 | # if defined(M_I86) && !defined(Z_SOLO)
129 | # include
130 | # endif
131 | #endif
132 |
133 | #if defined(MACOS) || defined(TARGET_OS_MAC)
134 | # define OS_CODE 7
135 | # ifndef Z_SOLO
136 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
137 | # include /* for fdopen */
138 | # else
139 | # ifndef fdopen
140 | # define fdopen(fd,mode) NULL /* No fdopen() */
141 | # endif
142 | # endif
143 | # endif
144 | #endif
145 |
146 | #ifdef __acorn
147 | # define OS_CODE 13
148 | #endif
149 |
150 | #if defined(WIN32) && !defined(__CYGWIN__)
151 | # define OS_CODE 10
152 | #endif
153 |
154 | #ifdef _BEOS_
155 | # define OS_CODE 16
156 | #endif
157 |
158 | #ifdef __TOS_OS400__
159 | # define OS_CODE 18
160 | #endif
161 |
162 | #ifdef __APPLE__
163 | # define OS_CODE 19
164 | #endif
165 |
166 | #if defined(_BEOS_) || defined(RISCOS)
167 | # define fdopen(fd,mode) NULL /* No fdopen() */
168 | #endif
169 |
170 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
171 | # if defined(_WIN32_WCE)
172 | # define fdopen(fd,mode) NULL /* No fdopen() */
173 | # ifndef _PTRDIFF_T_DEFINED
174 | typedef int ptrdiff_t;
175 | # define _PTRDIFF_T_DEFINED
176 | # endif
177 | # else
178 | # define fdopen(fd,type) _fdopen(fd,type)
179 | # endif
180 | #endif
181 |
182 | #if defined(__BORLANDC__) && !defined(MSDOS)
183 | #pragma warn -8004
184 | #pragma warn -8008
185 | #pragma warn -8066
186 | #endif
187 |
188 | /* provide prototypes for these when building zlib without LFS */
189 | #if !defined(_WIN32) && \
190 | (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0)
191 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
192 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
193 | #endif
194 |
195 | /* common defaults */
196 |
197 | #ifndef OS_CODE
198 | # define OS_CODE 3 /* assume Unix */
199 | #endif
200 |
201 | #ifndef F_OPEN
202 | # define F_OPEN(name, mode) fopen((name), (mode))
203 | #endif
204 |
205 | /* functions */
206 |
207 | #if defined(pyr) || defined(Z_SOLO)
208 | # define NO_MEMCPY
209 | #endif
210 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
211 | /* Use our own functions for small and medium model with MSC <= 5.0.
212 | * You may have to use the same strategy for Borland C (untested).
213 | * The __SC__ check is for Symantec.
214 | */
215 | # define NO_MEMCPY
216 | #endif
217 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
218 | # define HAVE_MEMCPY
219 | #endif
220 | #ifdef HAVE_MEMCPY
221 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
222 | # define zmemcpy _fmemcpy
223 | # define zmemcmp _fmemcmp
224 | # define zmemzero(dest, len) _fmemset(dest, 0, len)
225 | # else
226 | # define zmemcpy memcpy
227 | # define zmemcmp memcmp
228 | # define zmemzero(dest, len) memset(dest, 0, len)
229 | # endif
230 | #else
231 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
232 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
233 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
234 | #endif
235 |
236 | /* Diagnostic functions */
237 | #ifdef ZLIB_DEBUG
238 | # include
239 | extern int ZLIB_INTERNAL z_verbose;
240 | extern void ZLIB_INTERNAL z_error OF((char *m));
241 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
242 | # define Trace(x) {if (z_verbose>=0) fprintf x ;}
243 | # define Tracev(x) {if (z_verbose>0) fprintf x ;}
244 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
245 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
246 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
247 | #else
248 | # define Assert(cond,msg)
249 | # define Trace(x)
250 | # define Tracev(x)
251 | # define Tracevv(x)
252 | # define Tracec(c,x)
253 | # define Tracecv(c,x)
254 | #endif
255 |
256 | #ifndef Z_SOLO
257 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
258 | unsigned size));
259 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
260 | #endif
261 |
262 | #define ZALLOC(strm, items, size) \
263 | (*((strm)->zalloc))((strm)->opaque, (items), (size))
264 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
265 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
266 |
267 | /* Reverse the bytes in a 32-bit value */
268 | #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
269 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
270 |
271 | #endif /* ZUTIL_H */
272 |
--------------------------------------------------------------------------------