[U-Boot] [PATCH] zlib: fix code when DEBUG is defined
Giuseppe CONDORELLI
giuseppe.condorelli at st.com
Thu Sep 3 10:08:31 CEST 2009
Removed stdio.h inclusion and moved trace macros to use printf avoiding to
write debug informations to standard error.
Signed-off-by: Giuseppe Condorelli <giuseppe.condorelli at st.com>
---
lib_generic/zlib.c | 59 +++++++++++++++++++++++++--------------------------
1 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/lib_generic/zlib.c b/lib_generic/zlib.c
index 1b6db32..8dca594 100644
--- a/lib_generic/zlib.c
+++ b/lib_generic/zlib.c
@@ -27,6 +27,7 @@
#define ZLIB_INTERNAL
#include "u-boot/zlib.h"
+#include <common.h>
/* To avoid a build time warning */
#ifdef STDC
#include <malloc.h>
@@ -83,15 +84,14 @@ typedef unsigned long ulg;
/* Diagnostic functions */
#ifdef DEBUG
-#include <stdio.h>
extern int z_verbose;
extern void z_error OF((char *m));
#define Assert(cond,msg) {if(!(cond)) z_error(msg);}
-#define Trace(x) {if (z_verbose>=0) fprintf x ;}
-#define Tracev(x) {if (z_verbose>0) fprintf x ;}
-#define Tracevv(x) {if (z_verbose>1) fprintf x ;}
-#define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
-#define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
+#define Trace(x) {if (z_verbose>=0) printf x ;}
+#define Tracev(x) {if (z_verbose>0) printf x ;}
+#define Tracevv(x) {if (z_verbose>1) printf x ;}
+#define Tracec(c,x) {if (z_verbose>0 && (c)) printf x ;}
+#define Tracecv(c,x) {if (z_verbose>1 && (c)) printf x ;}
#else
#define Assert(cond,msg)
#define Trace(x)
@@ -502,7 +502,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
bits -= op;
op = (unsigned)(this.op);
if (op == 0) { /* literal */
- Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ Tracevv((this.val >= 0x20 && this.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", this.val));
PUP(out) = (unsigned char)(this.val);
@@ -519,7 +519,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
hold >>= op;
bits -= op;
}
- Tracevv((stderr, "inflate: length %u\n", len));
+ Tracevv(("inflate: length %u\n", len));
if (bits < 15) {
hold += (unsigned long)(PUP(in)) << bits;
bits += 8;
@@ -553,7 +553,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
#endif
hold >>= op;
bits -= op;
- Tracevv((stderr, "inflate: distance %u\n", dist));
+ Tracevv(("inflate: distance %u\n", dist));
op = (unsigned)(out - beg); /* max distance in output */
if (dist > op) { /* see if copy from window */
op = dist - op; /* distance back in window */
@@ -644,7 +644,7 @@ unsigned start; /* inflate()'s starting value for strm->avail_out */
goto dolen;
}
else if (op & 32) { /* end-of-block */
- Tracevv((stderr, "inflate: end of block\n"));
+ Tracevv(("inflate: end of block\n"));
state->mode = TYPE;
break;
}
@@ -1042,7 +1042,7 @@ z_streamp strm;
state->lencode = state->distcode = state->next = state->codes;
if (strm->outcb != Z_NULL)
(*strm->outcb)(Z_NULL, 0);
- Tracev((stderr, "inflate: reset\n"));
+ Tracev(("inflate: reset\n"));
return Z_OK;
}
@@ -1067,7 +1067,7 @@ int stream_size;
state = (struct inflate_state FAR *)
ZALLOC(strm, 1, sizeof(struct inflate_state));
if (state == Z_NULL) return Z_MEM_ERROR;
- Tracev((stderr, "inflate: allocated\n"));
+ Tracev(("inflate: allocated\n"));
strm->state = (struct internal_state FAR *)state;
if (windowBits < 0) {
state->wrap = 0;
@@ -1418,7 +1418,7 @@ int flush;
break;
}
state->dmax = 1U << len;
- Tracev((stderr, "inflate: zlib header ok\n"));
+ Tracev(("inflate: zlib header ok\n"));
strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = hold & 0x200 ? DICTID : TYPE;
INITBITS();
@@ -1576,18 +1576,18 @@ int flush;
DROPBITS(1);
switch (BITS(2)) {
case 0: /* stored block */
- Tracev((stderr, "inflate: stored block%s\n",
+ Tracev(("inflate: stored block%s\n",
state->last ? " (last)" : ""));
state->mode = STORED;
break;
case 1: /* fixed block */
fixedtables(state);
- Tracev((stderr, "inflate: fixed codes block%s\n",
+ Tracev(("inflate: fixed codes block%s\n",
state->last ? " (last)" : ""));
state->mode = LEN; /* decode codes */
break;
case 2: /* dynamic block */
- Tracev((stderr, "inflate: dynamic codes block%s\n",
+ Tracev(("inflate: dynamic codes block%s\n",
state->last ? " (last)" : ""));
state->mode = TABLE;
break;
@@ -1606,7 +1606,7 @@ int flush;
break;
}
state->length = (unsigned)hold & 0xffff;
- Tracev((stderr, "inflate: stored length %u\n",
+ Tracev(("inflate: stored length %u\n",
state->length));
INITBITS();
state->mode = COPY;
@@ -1624,7 +1624,7 @@ int flush;
state->length -= copy;
break;
}
- Tracev((stderr, "inflate: stored end\n"));
+ Tracev(("inflate: stored end\n"));
state->mode = TYPE;
break;
case TABLE:
@@ -1642,7 +1642,7 @@ int flush;
break;
}
#endif
- Tracev((stderr, "inflate: table sizes ok\n"));
+ Tracev(("inflate: table sizes ok\n"));
state->have = 0;
state->mode = LENLENS;
case LENLENS:
@@ -1663,7 +1663,7 @@ int flush;
state->mode = BAD;
break;
}
- Tracev((stderr, "inflate: code lengths ok\n"));
+ Tracev(("inflate: code lengths ok\n"));
state->have = 0;
state->mode = CODELENS;
case CODELENS:
@@ -1738,7 +1738,7 @@ int flush;
state->mode = BAD;
break;
}
- Tracev((stderr, "inflate: codes ok\n"));
+ Tracev(("inflate: codes ok\n"));
state->mode = LEN;
case LEN:
if (strm->outcb != Z_NULL) /* for watchdog (U-Boot) */
@@ -1767,14 +1767,14 @@ int flush;
DROPBITS(this.bits);
state->length = (unsigned)this.val;
if ((int)(this.op) == 0) {
- Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ Tracevv((this.val >= 0x20 && this.val < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", this.val));
state->mode = LIT;
break;
}
if (this.op & 32) {
- Tracevv((stderr, "inflate: end of block\n"));
+ Tracevv(("inflate: end of block\n"));
state->mode = TYPE;
break;
}
@@ -1791,7 +1791,7 @@ int flush;
state->length += BITS(state->extra);
DROPBITS(state->extra);
}
- Tracevv((stderr, "inflate: length %u\n", state->length));
+ Tracevv(("inflate: length %u\n", state->length));
state->mode = DIST;
case DIST:
for (;;) {
@@ -1836,7 +1836,7 @@ int flush;
state->mode = BAD;
break;
}
- Tracevv((stderr, "inflate: distance %u\n", state->offset));
+ Tracevv(("inflate: distance %u\n", state->offset));
state->mode = MATCH;
case MATCH:
if (left == 0) goto inf_leave;
@@ -1889,7 +1889,7 @@ int flush;
break;
}
INITBITS();
- Tracev((stderr, "inflate: check matches trailer\n"));
+ Tracev(("inflate: check matches trailer\n"));
}
#ifdef GUNZIP
state->mode = LENGTH;
@@ -1902,7 +1902,7 @@ int flush;
break;
}
INITBITS();
- Tracev((stderr, "inflate: length matches trailer\n"));
+ Tracev(("inflate: length matches trailer\n"));
}
#endif
state->mode = DONE;
@@ -1961,7 +1961,7 @@ z_streamp strm;
}
ZFREE(strm, strm->state);
strm->state = Z_NULL;
- Tracev((stderr, "inflate: end\n"));
+ Tracev(("inflate: end\n"));
return Z_OK;
}
@@ -1999,8 +1999,7 @@ int z_verbose = verbose;
void z_error (m)
char *m;
{
- fprintf(stderr, "%s\n", m);
- exit(1);
+ printf("%s\n", m);
}
#endif
--
1.6.0.6
More information about the U-Boot
mailing list