aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-09-27 06:46:02 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-09-27 06:46:02 +0000
commit8d1edc20766dc9ece1969428635dcc364d25ee47 (patch)
treea53d807aeb25003e5a8ea22461079a10b5238e4d /libbb
parent4c8b42b7584fd03b1e81933ec0fdb58107370d8b (diff)
downloadbusybox-w32-8d1edc20766dc9ece1969428635dcc364d25ee47.tar.gz
busybox-w32-8d1edc20766dc9ece1969428635dcc364d25ee47.tar.bz2
busybox-w32-8d1edc20766dc9ece1969428635dcc364d25ee47.zip
Fix compress support and prevent a segfault
git-svn-id: svn://busybox.net/trunk/busybox@5599 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/uncompress.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/libbb/uncompress.c b/libbb/uncompress.c
index 903e6aa6d..949e27df1 100644
--- a/libbb/uncompress.c
+++ b/libbb/uncompress.c
@@ -28,8 +28,9 @@
28 * [... History snipped ...] 28 * [... History snipped ...]
29 * 29 *
30 */ 30 */
31#include <stdio.h> 31#include <stdio.h>
32 32#include <string.h>
33#include <unistd.h>
33 34
34#define IBUFSIZ 2048 /* Defailt input buffer size */ 35#define IBUFSIZ 2048 /* Defailt input buffer size */
35#define OBUFSIZ 2048 /* Default output buffer size */ 36#define OBUFSIZ 2048 /* Default output buffer size */
@@ -95,9 +96,6 @@ unsigned short codetab[HSIZE];
95#define clear_tab_prefixof() memset(codetab, 0, 256); 96#define clear_tab_prefixof() memset(codetab, 0, 256);
96 97
97 98
98extern int uncompress ( FILE *, FILE * );
99
100
101/* 99/*
102 * Decompress stdin to stdout. This routine adapts to the codes in the 100 * Decompress stdin to stdout. This routine adapts to the codes in the
103 * file building the "string" table on-the-fly; requiring no table to 101 * file building the "string" table on-the-fly; requiring no table to
@@ -105,7 +103,7 @@ extern int uncompress ( FILE *, FILE * );
105 * with those of the compress() routine. See the definitions above. 103 * with those of the compress() routine. See the definitions above.
106 */ 104 */
107 105
108int uncompress ( FILE * fdin, FILE * fdout ) 106extern int uncompress(int fd_in, int fd_out)
109{ 107{
110 char_type *stackp; 108 char_type *stackp;
111 code_int code; 109 code_int code;
@@ -125,7 +123,7 @@ int uncompress ( FILE * fdin, FILE * fdout )
125 123
126 insize = 0; 124 insize = 0;
127 125
128 inbuf [0] = fgetc(fdin); 126 inbuf [0] = xread_char(fd_in);
129 127
130 maxbits = inbuf[0] & BIT_MASK; 128 maxbits = inbuf[0] & BIT_MASK;
131 block_mode = inbuf[0] & BLOCK_MODE; 129 block_mode = inbuf[0] & BLOCK_MODE;
@@ -173,11 +171,7 @@ resetbuf: ;
173 171
174 if (insize < (int) sizeof(inbuf)-IBUFSIZ) 172 if (insize < (int) sizeof(inbuf)-IBUFSIZ)
175 { 173 {
176 rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin); 174 xread_all(fd_in, inbuf+insize, IBUFSIZ);
177
178 if ( !rsize && ferror(fdin))
179 return -1;
180
181 insize += rsize; 175 insize += rsize;
182 } 176 }
183 177
@@ -275,8 +269,7 @@ resetbuf: ;
275 269
276 if (outpos >= OBUFSIZ) 270 if (outpos >= OBUFSIZ)
277 { 271 {
278 fwrite(outbuf, 1,outpos,fdout); 272 write(fd_out, outbuf, outpos);
279
280 outpos = 0; 273 outpos = 0;
281 } 274 }
282 stackp+= i; 275 stackp+= i;
@@ -303,8 +296,9 @@ resetbuf: ;
303 } 296 }
304 while (rsize > 0); 297 while (rsize > 0);
305 298
306 if (outpos > 0) 299 if (outpos > 0) {
307 fwrite(outbuf, outpos,1, fdout); 300 write(fd_out, outbuf, outpos);
301 }
308 302
309 return 0; 303 return 0;
310} 304}