summaryrefslogtreecommitdiff
path: root/sys/lib/libz
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2004-06-30 15:44:55 +0000
committerchristos <christos@NetBSD.org>2004-06-30 15:44:55 +0000
commit75c2e1e75a2569d28ed458206efb7eb42e36b3cf (patch)
tree6879c1b69843b4c127899e47891a1db4545d156e /sys/lib/libz
parent45879fd71c3008598fd72e2814350a8312a0c5ba (diff)
Introduce a zerror() function that can be conditionally compiled out to
save space. share all error strings in a single array.
Diffstat (limited to 'sys/lib/libz')
-rw-r--r--sys/lib/libz/infblock.c10
-rw-r--r--sys/lib/libz/infcodes.c6
-rw-r--r--sys/lib/libz/inffast.c6
-rw-r--r--sys/lib/libz/inftrees.c16
-rw-r--r--sys/lib/libz/infutil.c26
-rw-r--r--sys/lib/libz/zutil.h30
6 files changed, 72 insertions, 22 deletions
diff --git a/sys/lib/libz/infblock.c b/sys/lib/libz/infblock.c
index 626f96d193b..6b0c0891fb9 100644
--- a/sys/lib/libz/infblock.c
+++ b/sys/lib/libz/infblock.c
@@ -1,4 +1,4 @@
-/* $NetBSD: infblock.c,v 1.6 2003/03/25 22:48:44 mycroft Exp $ */
+/* $NetBSD: infblock.c,v 1.7 2004/06/30 15:44:55 christos Exp $ */
/* infblock.c -- interpret and process block types to last block
* Copyright (C) 1995-2002 Mark Adler
@@ -178,7 +178,7 @@ int r;
case 3: /* illegal */
DUMPBITS(3)
s->mode = BAD;
- z->msg = (char*)"invalid block type";
+ z->msg = _ZERROR(_ZERR_INV_BLOCK);
r = Z_DATA_ERROR;
LEAVE
}
@@ -188,7 +188,7 @@ int r;
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
{
s->mode = BAD;
- z->msg = (char*)"invalid stored block lengths";
+ z->msg = _ZERROR(_ZERR_INV_BLOCK_LEN);
r = Z_DATA_ERROR;
LEAVE
}
@@ -221,7 +221,7 @@ int r;
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
{
s->mode = BAD;
- z->msg = (char*)"too many length or distance symbols";
+ z->msg = _ZERROR(_ZERR_TOO_MANY);
r = Z_DATA_ERROR;
LEAVE
}
@@ -293,7 +293,7 @@ int r;
{
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
- z->msg = (char*)"invalid bit length repeat";
+ z->msg = _ZERROR(_ZERR_INV_REPEAT);
r = Z_DATA_ERROR;
LEAVE
}
diff --git a/sys/lib/libz/infcodes.c b/sys/lib/libz/infcodes.c
index d16f6e4af5e..6327a0340df 100644
--- a/sys/lib/libz/infcodes.c
+++ b/sys/lib/libz/infcodes.c
@@ -1,4 +1,4 @@
-/* $NetBSD: infcodes.c,v 1.5 2003/03/18 20:00:47 mycroft Exp $ */
+/* $NetBSD: infcodes.c,v 1.6 2004/06/30 15:44:55 christos Exp $ */
/* infcodes.c -- process literals and length/distance pairs
* Copyright (C) 1995-2002 Mark Adler
@@ -155,7 +155,7 @@ int r;
break;
}
c->mode = BADCODE; /* invalid code */
- z->msg = (char*)"invalid literal/length code";
+ z->msg = _ZERROR(_ZERR_INV_LITERAL);
r = Z_DATA_ERROR;
LEAVE
case LENEXT: /* i: getting length extra (have base) */
@@ -187,7 +187,7 @@ int r;
break;
}
c->mode = BADCODE; /* invalid code */
- z->msg = (char*)"invalid distance code";
+ z->msg = _ZERROR(_ZERR_INV_DISTANCE);
r = Z_DATA_ERROR;
LEAVE
case DISTEXT: /* i: getting distance extra */
diff --git a/sys/lib/libz/inffast.c b/sys/lib/libz/inffast.c
index ebebe4bfe79..61b2b7ccfc7 100644
--- a/sys/lib/libz/inffast.c
+++ b/sys/lib/libz/inffast.c
@@ -1,4 +1,4 @@
-/* $NetBSD: inffast.c,v 1.5 2003/03/18 20:00:48 mycroft Exp $ */
+/* $NetBSD: inffast.c,v 1.6 2004/06/30 15:44:55 christos Exp $ */
/* inffast.c -- process literals and length/distance pairs fast
* Copyright (C) 1995-2002 Mark Adler
@@ -139,7 +139,7 @@ z_streamp z;
}
else
{
- z->msg = (char*)"invalid distance code";
+ z->msg = _ZERROR(_ZERR_INV_DISTANCE);
UNGRAB
UPDATE
return Z_DATA_ERROR;
@@ -170,7 +170,7 @@ z_streamp z;
}
else
{
- z->msg = (char*)"invalid literal/length code";
+ z->msg = _ZERROR(_ZERR_INV_LITERAL);
UNGRAB
UPDATE
return Z_DATA_ERROR;
diff --git a/sys/lib/libz/inftrees.c b/sys/lib/libz/inftrees.c
index 48d1ebf33fc..398910f3f46 100644
--- a/sys/lib/libz/inftrees.c
+++ b/sys/lib/libz/inftrees.c
@@ -1,4 +1,4 @@
-/* $NetBSD: inftrees.c,v 1.7 2003/08/31 22:40:49 fvdl Exp $ */
+/* $NetBSD: inftrees.c,v 1.8 2004/06/30 15:44:55 christos Exp $ */
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2002 Mark Adler
@@ -308,10 +308,10 @@ z_streamp z; /* for messages */
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR)
- z->msg = (char*)"oversubscribed dynamic bit lengths tree";
+ z->msg = _ZERROR(_ZERR_OVERSUB_DBIT);
else if (r == Z_BUF_ERROR || *bb == 0)
{
- z->msg = (char*)"incomplete dynamic bit lengths tree";
+ z->msg = _ZERROR(_ZERR_INCOMPLETE_DBIT);
r = Z_DATA_ERROR;
}
ZFREE(z, v);
@@ -343,10 +343,10 @@ z_streamp z; /* for messages */
if (r != Z_OK || *bl == 0)
{
if (r == Z_DATA_ERROR)
- z->msg = (char*)"oversubscribed literal/length tree";
+ z->msg = _ZERROR(_ZERR_OVERSUB_LIT);
else if (r != Z_MEM_ERROR)
{
- z->msg = (char*)"incomplete literal/length tree";
+ z->msg = _ZERROR(_ZERR_INCOMPLETE_LIT);
r = Z_DATA_ERROR;
}
ZFREE(z, v);
@@ -358,18 +358,18 @@ z_streamp z; /* for messages */
if (r != Z_OK || (*bd == 0 && nl > 257))
{
if (r == Z_DATA_ERROR)
- z->msg = (char*)"oversubscribed distance tree";
+ z->msg = _ZERROR(_ZERR_OVERSUB_DIST);
else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND
r = Z_OK;
}
#else
- z->msg = (char*)"incomplete distance tree";
+ z->msg = _ZERROR(_ZERR_INCOMPLETE_DIST);
r = Z_DATA_ERROR;
}
else if (r != Z_MEM_ERROR)
{
- z->msg = (char*)"empty distance tree with lengths";
+ z->msg = _ZERROR(_ZERR_EMPTY_DIST);
r = Z_DATA_ERROR;
}
ZFREE(z, v);
diff --git a/sys/lib/libz/infutil.c b/sys/lib/libz/infutil.c
index 9fba6a2ea60..07772a19f6f 100644
--- a/sys/lib/libz/infutil.c
+++ b/sys/lib/libz/infutil.c
@@ -1,4 +1,4 @@
-/* $NetBSD: infutil.c,v 1.6 2003/03/25 22:48:44 mycroft Exp $ */
+/* $NetBSD: infutil.c,v 1.7 2004/06/30 15:44:55 christos Exp $ */
/* inflate_util.c -- data and routines common to blocks and codes
* Copyright (C) 1995-2002 Mark Adler
@@ -21,6 +21,30 @@ const uInt inflate_mask[17] = {
};
+#ifndef _ZLIB_NO_ERRMSG
+static const char *const zerrlist[] = {
+ "invalid block type"
+ "invalid stored block lengths",
+ "too many length or distance symbols",
+ "invalid bit length repeat",
+ "invalid literal/length code",
+ "invalid distance code",
+ "oversubscribed dynamic bit lengths tree",
+ "incomplete dynamic bit lengths tree",
+ "oversubscribed literal/length tree",
+ "incomplete literal/length tree",
+ "oversubscribed distance tree",
+ "incomplete distance tree",
+ "empty distance tree with lengths",
+};
+
+char *zerror(e)
+ int e;
+{
+ return __DECONST(zerrlist[e]);
+}
+#endif
+
/* copy as much as possible from the sliding window to the output area */
int inflate_flush(s, z, r)
inflate_blocks_statef *s;
diff --git a/sys/lib/libz/zutil.h b/sys/lib/libz/zutil.h
index 9cfcca1c9ea..248f10387bf 100644
--- a/sys/lib/libz/zutil.h
+++ b/sys/lib/libz/zutil.h
@@ -1,4 +1,4 @@
-/* $NetBSD: zutil.h,v 1.10 2002/03/12 00:42:24 fvdl Exp $ */
+/* $NetBSD: zutil.h,v 1.11 2004/06/30 15:44:55 christos Exp $ */
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2002 Jean-loup Gailly.
@@ -10,7 +10,7 @@
subject to change. Applications should only use zlib.h.
*/
-/* @(#) $Id: zutil.h,v 1.10 2002/03/12 00:42:24 fvdl Exp $ */
+/* @(#) $Id: zutil.h,v 1.11 2004/06/30 15:44:55 christos Exp $ */
#ifndef _Z_UTIL_H
#define _Z_UTIL_H
@@ -226,4 +226,30 @@ void zcfree __P((voidpf opaque, voidpf ptr));
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+#ifndef _ZLIB_NO_ERRMSG
+
+#define _ZERR_INV_BLOCK 0
+#define _ZERR_INV_BLOCK_LEN 1
+#define _ZERR_TOO_MANY 2
+#define _ZERR_INV_REPEAT 3
+#define _ZERR_INV_LITERAL 4
+#define _ZERR_INV_DISTANCE 5
+#define _ZERR_OVERSUB_DBIT 6
+#define _ZERR_INCOMPLETE_DBIT 7
+#define _ZERR_OVERSUB_LIT 8
+#define _ZERR_INCOMPLETE_LIT 9
+#define _ZERR_OVERSUB_DIST 10
+#define _ZERR_INCOMPLETE_DIST 11
+#define _ZERR_EMPTY_DIST 12
+#define _ZERR_MAX_ERRORS 13
+
+extern char *zerror __P((int));
+#define _ZERROR(a) zerror(a)
+
+#else
+
+#define _ZERROR(a) NULL
+
+#endif
+
#endif /* _Z_UTIL_H */