gitweb: Create Gitweb::Util module
[git/jnareb-git/bp-gitweb.git] / zlib.c
blobc4d58da4e9050c6330ff145914cc379f0600f703
1 /*
2 * zlib wrappers to make sure we don't silently miss errors
3 * at init time.
4 */
5 #include "cache.h"
7 void git_inflate_init(z_streamp strm)
9 const char *err;
11 switch (inflateInit(strm)) {
12 case Z_OK:
13 return;
15 case Z_MEM_ERROR:
16 err = "out of memory";
17 break;
18 case Z_VERSION_ERROR:
19 err = "wrong version";
20 break;
21 default:
22 err = "error";
24 die("inflateInit: %s (%s)", err, strm->msg ? strm->msg : "no message");
27 void git_inflate_end(z_streamp strm)
29 if (inflateEnd(strm) != Z_OK)
30 error("inflateEnd: %s", strm->msg ? strm->msg : "failed");
33 int git_inflate(z_streamp strm, int flush)
35 int ret = inflate(strm, flush);
36 const char *err;
38 switch (ret) {
39 /* Out of memory is fatal. */
40 case Z_MEM_ERROR:
41 die("inflate: out of memory");
43 /* Data corruption errors: we may want to recover from them (fsck) */
44 case Z_NEED_DICT:
45 err = "needs dictionary"; break;
46 case Z_DATA_ERROR:
47 err = "data stream error"; break;
48 case Z_STREAM_ERROR:
49 err = "stream consistency error"; break;
50 default:
51 err = "unknown error"; break;
53 /* Z_BUF_ERROR: normal, needs more space in the output buffer */
54 case Z_BUF_ERROR:
55 case Z_OK:
56 case Z_STREAM_END:
57 return ret;
59 error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message");
60 return ret;