From ab9eef21a57c23567505e8fbceb8e5ea76306ce1 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Wed, 7 Mar 2007 22:02:23 +0000 Subject: bunzip2/gunzip/uncompress/unlzma: merge into common code - fix few corner cases, reduce size by 450 bytes. Update testsuite. --- archival/unlzma.c | 65 ------------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 archival/unlzma.c (limited to 'archival/unlzma.c') diff --git a/archival/unlzma.c b/archival/unlzma.c deleted file mode 100644 index 24632c4a7..000000000 --- a/archival/unlzma.c +++ /dev/null @@ -1,65 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Small lzma deflate implementation. - * Copyright (C) 2006 Aurelien Jacobs - * - * Based on bunzip.c from busybox - * - * Licensed under GPL v2, see file LICENSE in this tarball for details. - */ - -/* Why our g[un]zip/bunzip2 are so ugly compared to this beauty? */ - -#include "busybox.h" -#include "unarchive.h" - -#define UNLZMA_OPT_STDOUT 1 - -int unlzma_main(int argc, char **argv); -int unlzma_main(int argc, char **argv) -{ - USE_DESKTOP(long long) int status; - char *filename; - unsigned opt; - int src_fd, dst_fd; - - opt = getopt32(argc, argv, "c"); - - /* Set input filename and number */ - filename = argv[optind]; - if (filename && NOT_LONE_DASH(filename)) { - /* Open input file */ - src_fd = xopen(filename, O_RDONLY); - } else { - src_fd = STDIN_FILENO; - filename = 0; - } - - /* if called as lzmacat force the stdout flag */ - if ((opt & UNLZMA_OPT_STDOUT) || applet_name[4] == 'c') - filename = 0; - - if (filename) { - struct stat stat_buf; - /* bug: char *extension = filename + strlen(filename) - 5; */ - char *extension = strrchr(filename, '.'); - if (!extension || strcmp(extension, ".lzma") != 0) { - bb_error_msg_and_die("invalid extension"); - } - xstat(filename, &stat_buf); - *extension = '\0'; - dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC, - stat_buf.st_mode); - } else - dst_fd = STDOUT_FILENO; - status = unlzma(src_fd, dst_fd); - if (filename) { - if (status >= 0) /* if success delete src, else delete dst */ - filename[strlen(filename)] = '.'; - if (unlink(filename) < 0) { - bb_error_msg_and_die("cannot remove %s", filename); - } - } - - return (status < 0); -} -- cgit v1.2.3