diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-09-27 06:46:02 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-09-27 06:46:02 +0000 |
commit | 2e41d0cb777e6af086b45555551780e02ad13f46 (patch) | |
tree | a53d807aeb25003e5a8ea22461079a10b5238e4d /archival/libunarchive/decompress_uncompress.c | |
parent | a47a3eada6ada1168205f6684e5c5a5c23d3558b (diff) |
Fix compress support and prevent a segfault
Diffstat (limited to 'archival/libunarchive/decompress_uncompress.c')
-rw-r--r-- | archival/libunarchive/decompress_uncompress.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c index 903e6aa6d..949e27df1 100644 --- a/archival/libunarchive/decompress_uncompress.c +++ b/archival/libunarchive/decompress_uncompress.c @@ -28,8 +28,9 @@ * [... History snipped ...] * */ -#include <stdio.h> - +#include <stdio.h> +#include <string.h> +#include <unistd.h> #define IBUFSIZ 2048 /* Defailt input buffer size */ #define OBUFSIZ 2048 /* Default output buffer size */ @@ -95,9 +96,6 @@ unsigned short codetab[HSIZE]; #define clear_tab_prefixof() memset(codetab, 0, 256); -extern int uncompress ( FILE *, FILE * ); - - /* * Decompress stdin to stdout. This routine adapts to the codes in the * file building the "string" table on-the-fly; requiring no table to @@ -105,7 +103,7 @@ extern int uncompress ( FILE *, FILE * ); * with those of the compress() routine. See the definitions above. */ -int uncompress ( FILE * fdin, FILE * fdout ) +extern int uncompress(int fd_in, int fd_out) { char_type *stackp; code_int code; @@ -125,7 +123,7 @@ int uncompress ( FILE * fdin, FILE * fdout ) insize = 0; - inbuf [0] = fgetc(fdin); + inbuf [0] = xread_char(fd_in); maxbits = inbuf[0] & BIT_MASK; block_mode = inbuf[0] & BLOCK_MODE; @@ -173,11 +171,7 @@ resetbuf: ; if (insize < (int) sizeof(inbuf)-IBUFSIZ) { - rsize = fread(inbuf+insize, 1,IBUFSIZ,fdin); - - if ( !rsize && ferror(fdin)) - return -1; - + xread_all(fd_in, inbuf+insize, IBUFSIZ); insize += rsize; } @@ -275,8 +269,7 @@ resetbuf: ; if (outpos >= OBUFSIZ) { - fwrite(outbuf, 1,outpos,fdout); - + write(fd_out, outbuf, outpos); outpos = 0; } stackp+= i; @@ -303,8 +296,9 @@ resetbuf: ; } while (rsize > 0); - if (outpos > 0) - fwrite(outbuf, outpos,1, fdout); + if (outpos > 0) { + write(fd_out, outbuf, outpos); + } return 0; } |