diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2000-12-10 00:51:42 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2000-12-10 00:51:42 +0000 |
commit | 00732b57c7392df0fad6fbe392628e3f2174ea57 (patch) | |
tree | 69f529a5006af3c9b46d5523d035822b5ecbea66 /archival/gunzip.c | |
parent | c52a97d79fc6852abe1c04b3c4873a38ea443384 (diff) | |
download | busybox-w32-00732b57c7392df0fad6fbe392628e3f2174ea57.tar.gz busybox-w32-00732b57c7392df0fad6fbe392628e3f2174ea57.tar.bz2 busybox-w32-00732b57c7392df0fad6fbe392628e3f2174ea57.zip |
Introduce new function gunzip_init()
gunzip_init() will make it easier to use gunzip from other bb functions.
Diffstat (limited to 'archival/gunzip.c')
-rw-r--r-- | archival/gunzip.c | 67 |
1 files changed, 35 insertions, 32 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) | |||
1176 | bytes_in = bytes_out = 0L; | 1176 | bytes_in = bytes_out = 0L; |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | /* =========================================================================== | ||
1180 | * Initialize gunzip buffers and signals | ||
1181 | */ | ||
1182 | static int gunzip_init() | ||
1183 | { | ||
1184 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | ||
1185 | if (foreground) { | ||
1186 | (void) signal(SIGINT, (sig_type) abort_gzip); | ||
1187 | } | ||
1188 | #ifdef SIGTERM | ||
1189 | if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { | ||
1190 | (void) signal(SIGTERM, (sig_type) abort_gzip); | ||
1191 | } | ||
1192 | #endif | ||
1193 | #ifdef SIGHUP | ||
1194 | if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { | ||
1195 | (void) signal(SIGHUP, (sig_type) abort_gzip); | ||
1196 | } | ||
1197 | #endif | ||
1198 | |||
1199 | /* Allocate all global buffers (for DYN_ALLOC option) */ | ||
1200 | inbuf = xmalloc((size_t)((INBUFSIZ+INBUF_EXTRA+1L)*sizeof(uch))); | ||
1201 | outbuf = xmalloc((size_t)((OUTBUFSIZ+OUTBUF_EXTRA+1L)*sizeof(uch))); | ||
1202 | d_buf = xmalloc((size_t)((DIST_BUFSIZE+1L)*sizeof(ush))); | ||
1203 | window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(uch))); | ||
1204 | tab_prefix0 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); | ||
1205 | tab_prefix1 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); | ||
1206 | |||
1207 | clear_bufs(); /* clear input and output buffers */ | ||
1208 | part_nb = 0; | ||
1209 | return(EXIT_SUCCESS); | ||
1210 | } | ||
1211 | |||
1212 | |||
1179 | /* ======================================================================== */ | 1213 | /* ======================================================================== */ |
1180 | int gunzip_main(int argc, char **argv) | 1214 | int gunzip_main(int argc, char **argv) |
1181 | { | 1215 | { |
1182 | int file_count; /* number of files to precess */ | ||
1183 | int tostdout = 0; | 1216 | int tostdout = 0; |
1184 | int fromstdin = 0; | 1217 | int fromstdin = 0; |
1185 | int result; | 1218 | int result; |
@@ -1229,31 +1262,7 @@ int gunzip_main(int argc, char **argv) | |||
1229 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) | 1262 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) |
1230 | error_msg_and_die( "data not written to terminal. Use -f to force it.\n"); | 1263 | error_msg_and_die( "data not written to terminal. Use -f to force it.\n"); |
1231 | 1264 | ||
1232 | 1265 | gunzip_init(); | |
1233 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | ||
1234 | if (foreground) { | ||
1235 | (void) signal(SIGINT, (sig_type) abort_gzip); | ||
1236 | } | ||
1237 | #ifdef SIGTERM | ||
1238 | if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { | ||
1239 | (void) signal(SIGTERM, (sig_type) abort_gzip); | ||
1240 | } | ||
1241 | #endif | ||
1242 | #ifdef SIGHUP | ||
1243 | if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { | ||
1244 | (void) signal(SIGHUP, (sig_type) abort_gzip); | ||
1245 | } | ||
1246 | #endif | ||
1247 | |||
1248 | file_count = argc - optind; | ||
1249 | |||
1250 | /* Allocate all global buffers (for DYN_ALLOC option) */ | ||
1251 | inbuf = xmalloc((size_t)((INBUFSIZ+INBUF_EXTRA+1L)*sizeof(uch))); | ||
1252 | outbuf = xmalloc((size_t)((OUTBUFSIZ+OUTBUF_EXTRA+1L)*sizeof(uch))); | ||
1253 | d_buf = xmalloc((size_t)((DIST_BUFSIZE+1L)*sizeof(ush))); | ||
1254 | window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(uch))); | ||
1255 | tab_prefix0 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); | ||
1256 | tab_prefix1 = xmalloc((size_t)(((1L<<(BITS-1))+1L)*sizeof(ush))); | ||
1257 | 1266 | ||
1258 | if (fromstdin == 1) { | 1267 | if (fromstdin == 1) { |
1259 | strcpy(ofname, "stdin"); | 1268 | strcpy(ofname, "stdin"); |
@@ -1290,9 +1299,6 @@ int gunzip_main(int argc, char **argv) | |||
1290 | strcpy(ofname, "stdout"); | 1299 | strcpy(ofname, "stdout"); |
1291 | outFileNum = fileno(stdout); | 1300 | outFileNum = fileno(stdout); |
1292 | 1301 | ||
1293 | clear_bufs(); /* clear input and output buffers */ | ||
1294 | part_nb = 0; | ||
1295 | |||
1296 | /* Actually do the compression/decompression. */ | 1302 | /* Actually do the compression/decompression. */ |
1297 | unzip(inFileNum, outFileNum); | 1303 | unzip(inFileNum, outFileNum); |
1298 | 1304 | ||
@@ -1334,9 +1340,6 @@ int gunzip_main(int argc, char **argv) | |||
1334 | /* Set permissions on the file */ | 1340 | /* Set permissions on the file */ |
1335 | fchmod(outFileNum, statBuf.st_mode); | 1341 | fchmod(outFileNum, statBuf.st_mode); |
1336 | 1342 | ||
1337 | clear_bufs(); /* clear input and output buffers */ | ||
1338 | part_nb = 0; | ||
1339 | |||
1340 | /* Actually do the compression/decompression. */ | 1343 | /* Actually do the compression/decompression. */ |
1341 | result = unzip(inFileNum, outFileNum); | 1344 | result = unzip(inFileNum, outFileNum); |
1342 | 1345 | ||