summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorGlenn L McGrath2000-12-10 00:51:42 +0000
committerGlenn L McGrath2000-12-10 00:51:42 +0000
commit00732b57c7392df0fad6fbe392628e3f2174ea57 (patch)
tree69f529a5006af3c9b46d5523d035822b5ecbea66 /archival
parentc52a97d79fc6852abe1c04b3c4873a38ea443384 (diff)
downloadbusybox-00732b57c7392df0fad6fbe392628e3f2174ea57.zip
busybox-00732b57c7392df0fad6fbe392628e3f2174ea57.tar.gz
Introduce new function gunzip_init()
gunzip_init() will make it easier to use gunzip from other bb functions.
Diffstat (limited to 'archival')
-rw-r--r--archival/gunzip.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c
index a5846c3..48db7cf 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);