From 00732b57c7392df0fad6fbe392628e3f2174ea57 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Sun, 10 Dec 2000 00:51:42 +0000 Subject: [PATCH] Introduce new function gunzip_init() gunzip_init() will make it easier to use gunzip from other bb functions. --- archival/gunzip.c | 67 +++++++++++++++++++++++++---------------------- gunzip.c | 67 +++++++++++++++++++++++++---------------------- 2 files changed, 70 insertions(+), 64 deletions(-) diff --git a/archival/gunzip.c b/archival/gunzip.c index a5846c378..48db7cfd7 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c @@ -1176,10 +1176,43 @@ void clear_bufs(void) bytes_in = bytes_out = 0L; } +/* =========================================================================== + * Initialize gunzip buffers and signals + */ +static int gunzip_init() +{ + foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; + if (foreground) { + (void) signal(SIGINT, (sig_type) abort_gzip); + } +#ifdef SIGTERM + if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { + (void) signal(SIGTERM, (sig_type) abort_gzip); + } +#endif +#ifdef SIGHUP + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { + (void) signal(SIGHUP, (sig_type) abort_gzip); + } +#endif + + /* Allocate all global buffers (for DYN_ALLOC option) */ + inbuf = xmalloc((size_t)((INBUFSIZ+INBUF_EXTRA+1L)*sizeof(uch))); + outbuf = xmalloc((size_t)((OUTBUFSIZ+OUTBUF_EXTRA+1L)*sizeof(uch))); + d_buf = xmalloc((size_t)((DIST_BUFSIZE+1L)*sizeof(ush))); + window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(uch))); + tab_prefix0 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); + tab_prefix1 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); + + clear_bufs(); /* clear input and output buffers */ + part_nb = 0; + return(EXIT_SUCCESS); +} + + /* ======================================================================== */ int gunzip_main(int argc, char **argv) { - int file_count; /* number of files to precess */ int tostdout = 0; int fromstdin = 0; int result; @@ -1229,31 +1262,7 @@ int gunzip_main(int argc, char **argv) if (isatty(fileno(stdout)) && tostdout==1 && force==0) error_msg_and_die( "data not written to terminal. Use -f to force it.\n"); - - foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; - if (foreground) { - (void) signal(SIGINT, (sig_type) abort_gzip); - } -#ifdef SIGTERM - if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { - (void) signal(SIGTERM, (sig_type) abort_gzip); - } -#endif -#ifdef SIGHUP - if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { - (void) signal(SIGHUP, (sig_type) abort_gzip); - } -#endif - - file_count = argc - optind; - - /* Allocate all global buffers (for DYN_ALLOC option) */ - inbuf = xmalloc((size_t)((INBUFSIZ+INBUF_EXTRA+1L)*sizeof(uch))); - outbuf = xmalloc((size_t)((OUTBUFSIZ+OUTBUF_EXTRA+1L)*sizeof(uch))); - d_buf = xmalloc((size_t)((DIST_BUFSIZE+1L)*sizeof(ush))); - window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(uch))); - tab_prefix0 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); - tab_prefix1 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); + gunzip_init(); if (fromstdin == 1) { strcpy(ofname, "stdin"); @@ -1290,9 +1299,6 @@ int gunzip_main(int argc, char **argv) strcpy(ofname, "stdout"); outFileNum = fileno(stdout); - clear_bufs(); /* clear input and output buffers */ - part_nb = 0; - /* Actually do the compression/decompression. */ unzip(inFileNum, outFileNum); @@ -1334,9 +1340,6 @@ int gunzip_main(int argc, char **argv) /* Set permissions on the file */ fchmod(outFileNum, statBuf.st_mode); - clear_bufs(); /* clear input and output buffers */ - part_nb = 0; - /* Actually do the compression/decompression. */ result = unzip(inFileNum, outFileNum); diff --git a/gunzip.c b/gunzip.c index a5846c378..48db7cfd7 100644 --- a/gunzip.c +++ b/gunzip.c @@ -1176,10 +1176,43 @@ void clear_bufs(void) bytes_in = bytes_out = 0L; } +/* =========================================================================== + * Initialize gunzip buffers and signals + */ +static int gunzip_init() +{ + foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; + if (foreground) { + (void) signal(SIGINT, (sig_type) abort_gzip); + } +#ifdef SIGTERM + if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { + (void) signal(SIGTERM, (sig_type) abort_gzip); + } +#endif +#ifdef SIGHUP + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { + (void) signal(SIGHUP, (sig_type) abort_gzip); + } +#endif + + /* Allocate all global buffers (for DYN_ALLOC option) */ + inbuf = xmalloc((size_t)((INBUFSIZ+INBUF_EXTRA+1L)*sizeof(uch))); + outbuf = xmalloc((size_t)((OUTBUFSIZ+OUTBUF_EXTRA+1L)*sizeof(uch))); + d_buf = xmalloc((size_t)((DIST_BUFSIZE+1L)*sizeof(ush))); + window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(uch))); + tab_prefix0 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); + tab_prefix1 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); + + clear_bufs(); /* clear input and output buffers */ + part_nb = 0; + return(EXIT_SUCCESS); +} + + /* ======================================================================== */ int gunzip_main(int argc, char **argv) { - int file_count; /* number of files to precess */ int tostdout = 0; int fromstdin = 0; int result; @@ -1229,31 +1262,7 @@ int gunzip_main(int argc, char **argv) if (isatty(fileno(stdout)) && tostdout==1 && force==0) error_msg_and_die( "data not written to terminal. Use -f to force it.\n"); - - foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; - if (foreground) { - (void) signal(SIGINT, (sig_type) abort_gzip); - } -#ifdef SIGTERM - if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { - (void) signal(SIGTERM, (sig_type) abort_gzip); - } -#endif -#ifdef SIGHUP - if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { - (void) signal(SIGHUP, (sig_type) abort_gzip); - } -#endif - - file_count = argc - optind; - - /* Allocate all global buffers (for DYN_ALLOC option) */ - inbuf = xmalloc((size_t)((INBUFSIZ+INBUF_EXTRA+1L)*sizeof(uch))); - outbuf = xmalloc((size_t)((OUTBUFSIZ+OUTBUF_EXTRA+1L)*sizeof(uch))); - d_buf = xmalloc((size_t)((DIST_BUFSIZE+1L)*sizeof(ush))); - window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(uch))); - tab_prefix0 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); - tab_prefix1 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); + gunzip_init(); if (fromstdin == 1) { strcpy(ofname, "stdin"); @@ -1290,9 +1299,6 @@ int gunzip_main(int argc, char **argv) strcpy(ofname, "stdout"); outFileNum = fileno(stdout); - clear_bufs(); /* clear input and output buffers */ - part_nb = 0; - /* Actually do the compression/decompression. */ unzip(inFileNum, outFileNum); @@ -1334,9 +1340,6 @@ int gunzip_main(int argc, char **argv) /* Set permissions on the file */ fchmod(outFileNum, statBuf.st_mode); - clear_bufs(); /* clear input and output buffers */ - part_nb = 0; - /* Actually do the compression/decompression. */ result = unzip(inFileNum, outFileNum); -- 2.25.1