diff options
| author | Rob Landley <rob@landley.net> | 2005-08-30 20:26:17 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2005-08-30 20:26:17 +0000 |
| commit | c8b8a2d0cf1e38fc0c8b11b724bbdfcdf62fe65b (patch) | |
| tree | 5edc3e912ceddaced425d8e026353359d0df6b81 | |
| parent | c3386a43048907fb07fb28f2723c1efbacf4bd79 (diff) | |
| download | busybox-w32-c8b8a2d0cf1e38fc0c8b11b724bbdfcdf62fe65b.tar.gz busybox-w32-c8b8a2d0cf1e38fc0c8b11b724bbdfcdf62fe65b.tar.bz2 busybox-w32-c8b8a2d0cf1e38fc0c8b11b724bbdfcdf62fe65b.zip | |
Don't comment warnings, _FIX_ warnings. (And putting in #warnings about
other warnings is just gross.)
On a side note, while I was there, I made the code slightly smaller.
| -rw-r--r-- | archival/bunzip2.c | 70 |
1 files changed, 22 insertions, 48 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c index 5cd013c0c..740e26919 100644 --- a/archival/bunzip2.c +++ b/archival/bunzip2.c | |||
| @@ -2,19 +2,7 @@ | |||
| 2 | * Modified for busybox by Glenn McGrath <bug1@iinet.net.au> | 2 | * Modified for busybox by Glenn McGrath <bug1@iinet.net.au> |
| 3 | * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> | 3 | * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> |
| 4 | * | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify | 5 | * Licensed under GPL v2, see file LICENSE in this tarball for details. |
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | */ | 6 | */ |
| 19 | 7 | ||
| 20 | #include <fcntl.h> | 8 | #include <fcntl.h> |
| @@ -32,61 +20,47 @@ | |||
| 32 | 20 | ||
| 33 | int bunzip2_main(int argc, char **argv) | 21 | int bunzip2_main(int argc, char **argv) |
| 34 | { | 22 | { |
| 35 | char *compressed_name; | 23 | char *filename; |
| 36 | /* Note: Ignore the warning about save_name being used uninitialized. | ||
| 37 | * That is not the case, but gcc has trouble working that out... */ | ||
| 38 | #warning The save_name warning is OK, ignore it | ||
| 39 | char *save_name; | ||
| 40 | unsigned long opt; | 24 | unsigned long opt; |
| 41 | int status; | 25 | int status, src_fd, dst_fd; |
| 42 | int src_fd; | ||
| 43 | int dst_fd; | ||
| 44 | 26 | ||
| 45 | opt = bb_getopt_ulflags(argc, argv, "cf"); | 27 | opt = bb_getopt_ulflags(argc, argv, "cf"); |
| 46 | 28 | ||
| 47 | /* if called as bzcat force the stdout flag */ | ||
| 48 | if (bb_applet_name[2] == 'c') { | ||
| 49 | opt |= BUNZIP2_OPT_STDOUT; | ||
| 50 | } | ||
| 51 | |||
| 52 | /* Set input filename and number */ | 29 | /* Set input filename and number */ |
| 53 | compressed_name = argv[optind]; | 30 | filename = argv[optind]; |
| 54 | if ((compressed_name) && (compressed_name[0] != '-') && (compressed_name[1] != '\0')) { | 31 | if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) { |
| 55 | /* Open input file */ | 32 | /* Open input file */ |
| 56 | src_fd = bb_xopen(compressed_name, O_RDONLY); | 33 | src_fd = bb_xopen(filename, O_RDONLY); |
| 57 | } else { | 34 | } else { |
| 58 | src_fd = STDIN_FILENO; | 35 | src_fd = STDIN_FILENO; |
| 59 | opt |= BUNZIP2_OPT_STDOUT; | 36 | filename = 0; |
| 60 | } | 37 | } |
| 38 | |||
| 39 | /* if called as bzcat force the stdout flag */ | ||
| 40 | if ((opt & BUNZIP2_OPT_STDOUT) || bb_applet_name[2] == 'c') | ||
| 41 | filename = 0; | ||
| 61 | 42 | ||
| 62 | /* Check that the input is sane. */ | 43 | /* Check that the input is sane. */ |
| 63 | if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) { | 44 | if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) { |
| 64 | bb_error_msg_and_die("compressed data not read from terminal. Use -f to force it."); | 45 | bb_error_msg_and_die("compressed data not read from terminal. Use -f to force it."); |
| 65 | } | 46 | } |
| 66 | 47 | ||
| 67 | if (opt & BUNZIP2_OPT_STDOUT) { | 48 | if (filename) { |
| 68 | dst_fd = STDOUT_FILENO; | 49 | char *extension=filename+strlen(filename)-4; |
| 69 | } else { | 50 | if (strcmp(extension, ".bz2") != 0) { |
| 70 | int len = strlen(compressed_name) - 4; | ||
| 71 | if (strcmp(compressed_name + len, ".bz2") != 0) { | ||
| 72 | bb_error_msg_and_die("Invalid extension"); | 51 | bb_error_msg_and_die("Invalid extension"); |
| 73 | } | 52 | } |
| 74 | save_name = bb_xstrndup(compressed_name, len); | 53 | *extension=0; |
| 75 | dst_fd = bb_xopen(save_name, O_WRONLY | O_CREAT); | 54 | dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT); |
| 76 | } | 55 | } else dst_fd = STDOUT_FILENO; |
| 77 | |||
| 78 | status = uncompressStream(src_fd, dst_fd); | 56 | status = uncompressStream(src_fd, dst_fd); |
| 79 | if(!(opt & BUNZIP2_OPT_STDOUT)) { | 57 | if(filename) { |
| 80 | char *delete_name; | 58 | if (!status) filename[strlen(filename)]='.'; |
| 81 | if (status) { | 59 | if (unlink(filename) < 0) { |
| 82 | delete_name = save_name; | 60 | bb_error_msg_and_die("Couldn't remove %s", filename); |
| 83 | } else { | ||
| 84 | delete_name = compressed_name; | ||
| 85 | } | ||
| 86 | if (unlink(delete_name) < 0) { | ||
| 87 | bb_error_msg_and_die("Couldn't remove %s", delete_name); | ||
| 88 | } | 61 | } |
| 89 | } | 62 | } |
| 90 | 63 | ||
| 91 | return status; | 64 | return status; |
| 92 | } | 65 | } |
| 66 | /* vi:set ts=4: */ | ||
