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.
This commit is contained in:
Rob Landley 2005-08-30 20:26:17 +00:00
parent c3386a4304
commit c8b8a2d0cf

View File

@ -2,19 +2,7 @@
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au> * Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPL v2, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <fcntl.h> #include <fcntl.h>
@ -32,61 +20,47 @@
int bunzip2_main(int argc, char **argv) int bunzip2_main(int argc, char **argv)
{ {
char *compressed_name; char *filename;
/* Note: Ignore the warning about save_name being used uninitialized.
* That is not the case, but gcc has trouble working that out... */
#warning The save_name warning is OK, ignore it
char *save_name;
unsigned long opt; unsigned long opt;
int status; int status, src_fd, dst_fd;
int src_fd;
int dst_fd;
opt = bb_getopt_ulflags(argc, argv, "cf"); opt = bb_getopt_ulflags(argc, argv, "cf");
/* if called as bzcat force the stdout flag */
if (bb_applet_name[2] == 'c') {
opt |= BUNZIP2_OPT_STDOUT;
}
/* Set input filename and number */ /* Set input filename and number */
compressed_name = argv[optind]; filename = argv[optind];
if ((compressed_name) && (compressed_name[0] != '-') && (compressed_name[1] != '\0')) { if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */ /* Open input file */
src_fd = bb_xopen(compressed_name, O_RDONLY); src_fd = bb_xopen(filename, O_RDONLY);
} else { } else {
src_fd = STDIN_FILENO; src_fd = STDIN_FILENO;
opt |= BUNZIP2_OPT_STDOUT; filename = 0;
} }
/* if called as bzcat force the stdout flag */
if ((opt & BUNZIP2_OPT_STDOUT) || bb_applet_name[2] == 'c')
filename = 0;
/* Check that the input is sane. */ /* Check that the input is sane. */
if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) { if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) {
bb_error_msg_and_die("compressed data not read from terminal. Use -f to force it."); bb_error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
} }
if (opt & BUNZIP2_OPT_STDOUT) { if (filename) {
dst_fd = STDOUT_FILENO; char *extension=filename+strlen(filename)-4;
} else { if (strcmp(extension, ".bz2") != 0) {
int len = strlen(compressed_name) - 4;
if (strcmp(compressed_name + len, ".bz2") != 0) {
bb_error_msg_and_die("Invalid extension"); bb_error_msg_and_die("Invalid extension");
} }
save_name = bb_xstrndup(compressed_name, len); *extension=0;
dst_fd = bb_xopen(save_name, O_WRONLY | O_CREAT); dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT);
} } else dst_fd = STDOUT_FILENO;
status = uncompressStream(src_fd, dst_fd); status = uncompressStream(src_fd, dst_fd);
if(!(opt & BUNZIP2_OPT_STDOUT)) { if(filename) {
char *delete_name; if (!status) filename[strlen(filename)]='.';
if (status) { if (unlink(filename) < 0) {
delete_name = save_name; bb_error_msg_and_die("Couldn't remove %s", filename);
} else {
delete_name = compressed_name;
}
if (unlink(delete_name) < 0) {
bb_error_msg_and_die("Couldn't remove %s", delete_name);
} }
} }
return status; return status;
} }
/* vi:set ts=4: */