summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorMatt Kraai2002-03-27 17:46:44 +0000
committerMatt Kraai2002-03-27 17:46:44 +0000
commitcf32ac543c618dec10a01a14744cee6e306d430e (patch)
tree4f91dbf1dbce9140ecf4504f2005be1101a6d811 /archival
parent35d60421b4f61de9f5ed39c3057555e6f64d75a7 (diff)
downloadbusybox-cf32ac543c618dec10a01a14744cee6e306d430e.zip
busybox-cf32ac543c618dec10a01a14744cee6e306d430e.tar.gz
* archival/bunzip2.c (bunzip2_main): Remove compressed file.
* testsuite/bunzip2/bunzip2-removes-compressed-file: New.
Diffstat (limited to 'archival')
-rw-r--r--archival/bunzip2.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index 678779e..a7b41b7 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -2323,10 +2323,12 @@ int bunzip2_main(int argc, char **argv)
const int bunzip_force = 2;
int flags = 0;
int opt = 0;
+ int status;
FILE *src_stream;
FILE *dst_stream;
char *save_name = NULL;
+ char *delete_name = NULL;
/* if called as bzcat */
if (strcmp(applet_name, "bzcat") == 0)
@@ -2369,7 +2371,22 @@ int bunzip2_main(int argc, char **argv)
} else {
dst_stream = xfopen(save_name, "w");
}
- uncompressStream(src_stream, dst_stream);
- return(TRUE);
+ if (uncompressStream(src_stream, dst_stream)) {
+ if (save_name != NULL)
+ delete_name = argv[optind];
+ status = EXIT_SUCCESS;
+ } else {
+ if (save_name != NULL)
+ delete_name = save_name;
+ status = EXIT_FAILURE;
+ }
+
+ if (delete_name) {
+ if (unlink(delete_name) < 0) {
+ error_msg_and_die("Couldn't remove %s", delete_name);
+ }
+ }
+
+ return status;
}