1/*
2 * zlib wrappers to make sure we don't silently miss errors
3 * at init time.
4 */
5#include "cache.h"
6
7void git_inflate_init(z_streamp strm)
8{
9 const char *err;
10
11 switch (inflateInit(strm)) {
12 case Z_OK:
13 return;
14
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";
23 }
24 die("inflateInit: %s (%s)", err, strm->msg ? strm->msg : "no message");
25}
26
27void git_inflate_end(z_streamp strm)
28{
29 if (inflateEnd(strm) != Z_OK)
30 error("inflateEnd: %s", strm->msg ? strm->msg : "failed");
31}
32
33int git_inflate(z_streamp strm, int flush)
34{
35 int ret = inflate(strm, flush);
36 const char *err;
37
38 switch (ret) {
39 /* Out of memory is fatal. */
40 case Z_MEM_ERROR:
41 die("inflate: out of memory");
42
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;
52
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;
58 }
59 error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message");
60 return ret;
61}