Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
zlib_compat.h
Go to the documentation of this file.
1
11/* The zlib-ng library inflates/deflates streams 40% faster
12 * than the classic (and largely inactively maintained) zlib library.
13 * The two libraries have different APIs, although zlib-ng may also
14 * include a "compatibility mode" to offer the zlib API.
15 * Not all distributions include this mode.
16 *
17 * This header aims to smooth the use of both libraries when the differences
18 * don't matter, by using some strategic #defines and typedefs.
19 * It builds on and generalizes the work started in !15815.
20 *
21 * Usage guidelines:
22 * 1) unconditionally include this header instead of
23 * conditionally including either <zlib.h> or <zlib-ng.h>
24 * 2) wrap zlib-dependent blocks in #ifdef USE_ZLIB_OR_ZLIBNG ... #endif
25 * 2) use zlib_stream instead of either z_stream or zng_stream
26 * 3) use zlib_streamp instead of either z_streamp or zng_streamp
27 * 4) wrap the names of zlib functions in ZLIB_PREFIX()
28 * 5a) If you need code specific to zlib or zlib-ng, then use this pattern
29 * to prevent the potentially-present compatibility mode from causing
30 * trouble:
31 *
32 * #ifdef USE_ZLIB_OR_ZLIBNG
33 * #ifdef HAVE_ZLIBNG
34 * (zlib-ng specific code)
35 * #else
36 * (zlib specific code)
37 * #endif
38 * #endif
39 *
40 * 5b) ... but consider whether your use case is common enough that you could
41 * add an abstraction to this file instead.
42 */
43
44#ifndef __ZLIB_COMPAT_H__
45#define __ZLIB_COMPAT_H__
46
47#ifdef __cplusplus
48extern "C" {
49#endif /* __cplusplus */
50
51
52#if defined(HAVE_ZLIB) && !defined(HAVE_ZLIBNG)
53#define USE_ZLIB_OR_ZLIBNG
54#define ZLIB_CONST
55#define ZLIB_PREFIX(x) x
56#include <zlib.h>
57typedef z_stream zlib_stream;
58typedef z_streamp zlib_streamp;
59#endif /* defined(HAVE_ZLIB) && !defined(HAVE_ZLIBNG) */
60
61#ifdef HAVE_ZLIBNG
62#define USE_ZLIB_OR_ZLIBNG
63#define HAVE_INFLATEPRIME 1
64#define ZLIB_PREFIX(x) zng_ ## x
65#include <zlib-ng.h>
66typedef zng_stream zlib_stream;
67typedef zng_streamp zlib_streamp;
68#endif /* HAVE_ZLIBNG */
69
70
71#ifdef __cplusplus
72}
73#endif /* __cplusplus */
74
75#endif /* __ZLIB_COMPAT_H__ */