]> git.ipfire.org Git - thirdparty/git.git/blame - zlib.c
zlib: wrap remaining calls to direct inflate/inflateEnd
[thirdparty/git.git] / zlib.c
CommitLineData
b0613ce0
JN
1/*
2 * zlib wrappers to make sure we don't silently miss errors
3 * at init time.
4 */
5#include "cache.h"
6
1a507fc1 7static const char *zerr_to_string(int status)
b0613ce0 8{
1a507fc1 9 switch (status) {
b0613ce0 10 case Z_MEM_ERROR:
1a507fc1 11 return "out of memory";
b0613ce0 12 case Z_VERSION_ERROR:
1a507fc1
JH
13 return "wrong version";
14 case Z_NEED_DICT:
15 return "needs dictionary";
16 case Z_DATA_ERROR:
17 return "data stream error";
18 case Z_STREAM_ERROR:
19 return "stream consistency error";
b0613ce0 20 default:
1a507fc1 21 return "unknown error";
b0613ce0 22 }
b0613ce0
JN
23}
24
1a507fc1 25void git_inflate_init(z_streamp strm)
b0613ce0 26{
1a507fc1
JH
27 int status = inflateInit(strm);
28
29 if (status == Z_OK)
30 return;
31 die("inflateInit: %s (%s)", zerr_to_string(status),
32 strm->msg ? strm->msg : "no message");
b0613ce0
JN
33}
34
1a507fc1 35void git_inflate_end(z_streamp strm)
b0613ce0 36{
1a507fc1 37 int status = inflateEnd(strm);
b0613ce0 38
1a507fc1
JH
39 if (status == Z_OK)
40 return;
41 error("inflateEnd: %s (%s)", zerr_to_string(status),
42 strm->msg ? strm->msg : "no message");
43}
b0613ce0 44
1a507fc1
JH
45int git_inflate(z_streamp strm, int flush)
46{
47 int status = inflate(strm, flush);
b0613ce0 48
1a507fc1 49 switch (status) {
b0613ce0
JN
50 /* Z_BUF_ERROR: normal, needs more space in the output buffer */
51 case Z_BUF_ERROR:
52 case Z_OK:
53 case Z_STREAM_END:
1a507fc1
JH
54 return status;
55
56 case Z_MEM_ERROR:
57 die("inflate: out of memory");
58 default:
59 break;
b0613ce0 60 }
1a507fc1
JH
61 error("inflate: %s (%s)", zerr_to_string(status),
62 strm->msg ? strm->msg : "no message");
63 return status;
b0613ce0 64}