2 This file is part of the lzop file compressor.
4 Copyright (C) 1996..2003 Markus Franz Xaver Johannes Oberhumer
7 Markus F.X.J. Oberhumer <markus@oberhumer.com>
8 http://www.oberhumer.com/opensource/lzop/
10 lzop and the LZO library are free software; you can redistribute them
11 and/or modify them under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; see the file COPYING.
22 If not, write to the Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 "Minimalized" for busybox by Alain Knaff
28 //usage:#define lzop_trivial_usage
29 //usage: "[-cfvd123456789CF] [FILE]..."
30 //usage:#define lzop_full_usage "\n\n"
31 //usage: " -1..9 Compression level"
32 //usage: "\n -d Decompress"
33 //usage: "\n -c Write to stdout"
34 //usage: "\n -f Force"
35 //usage: "\n -v Verbose"
36 //usage: "\n -F Don't store or verify checksum"
37 //usage: "\n -C Also write checksum of compressed block"
39 //usage:#define lzopcat_trivial_usage
40 //usage: "[-vCF] [FILE]..."
41 //usage:#define lzopcat_full_usage "\n\n"
42 //usage: " -v Verbose"
43 //usage: "\n -F Don't store or verify checksum"
45 //usage:#define unlzop_trivial_usage
46 //usage: "[-cfvCF] [FILE]..."
47 //usage:#define unlzop_full_usage "\n\n"
48 //usage: " -c Write to stdout"
49 //usage: "\n -f Force"
50 //usage: "\n -v Verbose"
51 //usage: "\n -F Don't store or verify checksum"
54 #include "bb_archive.h"
55 #include "liblzo_interface.h"
57 /* lzo-2.03/src/lzo_ptr.h */
58 #define pd(a,b) ((unsigned)((a)-(b)))
60 #define lzo_version() LZO_VERSION
61 #define lzo_sizeof_dict_t (sizeof(uint8_t*))
63 /* lzo-2.03/include/lzo/lzo1x.h */
64 #define LZO1X_1_MEM_COMPRESS (16384 * lzo_sizeof_dict_t)
65 #define LZO1X_1_15_MEM_COMPRESS (32768 * lzo_sizeof_dict_t)
66 #define LZO1X_999_MEM_COMPRESS (14 * 16384 * sizeof(short))
68 /* lzo-2.03/src/lzo1x_oo.c */
69 #define NO_LIT UINT_MAX
71 /**********************************************************************/
72 static void copy2(uint8_t* ip, const uint8_t* m_pos, unsigned off)
81 static void copy3(uint8_t* ip, const uint8_t* m_pos, unsigned off)
85 ip[2] = ip[1] = m_pos[0];
97 /**********************************************************************/
98 // optimize a block of data.
99 /**********************************************************************/
100 #define TEST_IP (ip < ip_end)
101 #define TEST_OP (op <= op_end)
103 static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
104 uint8_t *out, unsigned *out_len,
105 void* wrkmem UNUSED_PARAM)
111 uint8_t* const ip_end = in + in_len;
112 uint8_t* const op_end = out + *out_len;
113 uint8_t* litp = NULL;
115 unsigned next_lit = NO_LIT;
117 unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
119 // LZO_UNUSED(wrkmem);
130 goto first_literal_run;
133 while (TEST_IP && TEST_OP) {
152 do *op++ = *ip++; while (--t > 0);
159 m_pos = op - 1 - 0x800;
161 m_pos = op - 1 - 0x400;
174 if (t < 16) { /* a M1 match */
183 /* test if a match follows */
184 if (nl == 0 && lit == 1 && ip[0] >= 16) {
186 /* adjust length of previous short run */
188 *litp = (unsigned char)((*litp & ~3) | lit);
189 /* copy over the 2 literals that replace the match */
190 copy2(ip-2, m_pos, pd(op, m_pos));
193 /* test if a literal run follows */
198 && (lit + 2 + ip[0] < 16)
201 /* remove short run */
203 /* copy over the 2 literals that replace the match */
204 copy2(ip-3+1, m_pos, pd(op, m_pos));
205 /* move literals 1 byte ahead */
208 memmove(litp+1, litp, lit);
209 /* insert new length of long literal run */
211 *litp = (unsigned char)(lit - 3);
216 goto copy_literal_run;
223 if (t >= 64) { /* a M2 match */
226 m_pos -= (t >> 2) & 7;
230 m_pos -= (t >> 2) & 3;
238 /* test if in beetween two long literal runs */
239 if (t == 1 && lit > 3 && nl == 0
240 && ip[0] < 16 && ip[0] != 0 && (lit + 3 + ip[0] < 16)
243 /* copy over the 3 literals that replace the match */
244 copy3(ip-1-2, m_pos, pd(op, m_pos));
245 /* set new length of previous literal run */
247 *litp = (unsigned char)(lit - 3);
252 goto copy_literal_run;
255 if (t >= 32) { /* a M3 match */
266 } else { /* a M4 match */
268 m_pos -= (t & 8) << 11;
286 /* test if in beetween two matches */
287 if (t == 1 && lit == 0 && nl == 0 && ip[0] >= 16) {
289 /* make a previous short run */
291 *litp = (unsigned char)((*litp & ~3) | lit);
292 /* copy over the 3 literals that replace the match */
293 copy3(ip-3, m_pos, pd(op, m_pos));
296 /* test if a literal run follows */
297 else if (t == 1 && lit <= 3 && nl == 0
298 && ip[0] < 16 && ip[0] != 0 && (lit + 3 + ip[0] < 16)
301 /* remove short run */
303 /* copy over the 3 literals that replace the match */
304 copy3(ip-4+1, m_pos, pd(op, m_pos));
305 /* move literals 1 byte ahead */
308 memmove(litp+1,litp,lit);
309 /* insert new length of long literal run */
311 *litp = (unsigned char)(lit - 3);
317 goto copy_literal_run;
323 do *op++ = *m_pos++; while (--t > 0);
327 if (next_lit == NO_LIT) {
339 do *op++ = *ip++; while (--t > 0);
341 } while (TEST_IP && TEST_OP);
344 /* no EOF code was found */
345 *out_len = pd(op, out);
346 return LZO_E_EOF_NOT_FOUND;
349 // LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2);
350 // LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b);
351 *out_len = pd(op, out);
352 return (ip == ip_end ? LZO_E_OK :
353 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
356 /**********************************************************************/
357 #define F_OS F_OS_UNIX
358 #define F_CS F_CS_NATIVE
360 /**********************************************************************/
361 #define ADLER32_INIT_VALUE 1
362 #define CRC32_INIT_VALUE 0
364 /**********************************************************************/
371 /**********************************************************************/
373 #define F_ADLER32_D 0x00000001L
374 #define F_ADLER32_C 0x00000002L
375 #define F_H_EXTRA_FIELD 0x00000040L
376 #define F_H_GMTDIFF 0x00000080L
377 #define F_CRC32_D 0x00000100L
378 #define F_CRC32_C 0x00000200L
379 #define F_H_FILTER 0x00000800L
380 #define F_H_CRC32 0x00001000L
381 #define F_MASK 0x00003FFFL
383 /* operating system & file system that created the file [mostly unused] */
384 #define F_OS_UNIX 0x03000000L
385 #define F_OS_SHIFT 24
386 #define F_OS_MASK 0xff000000L
388 /* character set for file name encoding [mostly unused] */
389 #define F_CS_NATIVE 0x00000000L
390 #define F_CS_SHIFT 20
391 #define F_CS_MASK 0x00f00000L
393 /* these bits must be zero */
394 #define F_RESERVED ((F_MASK | F_OS_MASK | F_CS_MASK) ^ 0xffffffffL)
396 typedef struct chksum_t {
401 typedef struct header_t {
403 unsigned lib_version;
404 unsigned version_needed_to_extract;
409 uint32_t header_checksum;
411 uint32_t extra_field_len;
412 uint32_t extra_field_checksum;
414 unsigned char method;
422 /*const uint32_t *lzo_crc32_table;*/
426 #define G (*(struct globals*)&bb_common_bufsiz1)
427 #define INIT_G() do { } while (0)
428 //#define G (*ptr_to_globals)
429 //#define INIT_G() do {
430 // SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
434 /**********************************************************************/
435 #define LZOP_VERSION 0x1010
436 //#define LZOP_VERSION_STRING "1.01"
437 //#define LZOP_VERSION_DATE "Apr 27th 2003"
439 #define OPTION_STRING "cfvdt123456789CF"
442 OPT_STDOUT = (1 << 0),
443 OPT_FORCE = (1 << 1),
444 OPT_VERBOSE = (1 << 2),
445 OPT_DECOMPRESS = (1 << 3),
460 /**********************************************************************/
462 // adapted from free code by Mark Adler <madler@alumni.caltech.edu>
463 // see http://www.zlib.org/
464 /**********************************************************************/
465 static FAST_FUNC uint32_t
466 lzo_adler32(uint32_t adler, const uint8_t* buf, unsigned len)
469 LZO_BASE = 65521, /* largest prime smaller than 65536 */
470 /* NMAX is the largest n such that
471 * 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
474 uint32_t s1 = adler & 0xffff;
475 uint32_t s2 = (adler >> 16) & 0xffff;
482 k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
491 return (s2 << 16) | s1;
494 static FAST_FUNC uint32_t
495 lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
497 //if (buf == NULL) - impossible
500 return ~crc32_block_endian0(~c, buf, len, global_crc32_table);
503 /**********************************************************************/
504 static void init_chksum(chksum_t *ct)
506 ct->f_adler32 = ADLER32_INIT_VALUE;
507 ct->f_crc32 = CRC32_INIT_VALUE;
510 static void add_bytes_to_chksum(chksum_t *ct, const void* buf, int cnt)
512 /* We need to handle the two checksums at once, because at the
513 * beginning of the header, we don't know yet which one we'll
515 ct->f_adler32 = lzo_adler32(ct->f_adler32, (const uint8_t*)buf, cnt);
516 ct->f_crc32 = lzo_crc32(ct->f_crc32, (const uint8_t*)buf, cnt);
519 static uint32_t chksum_getresult(chksum_t *ct, const header_t *h)
521 return (h->flags & F_H_CRC32) ? ct->f_crc32 : ct->f_adler32;
524 /**********************************************************************/
525 static uint32_t read32(void)
532 static void write32(uint32_t v)
538 static void f_write(const void* buf, int cnt)
541 add_bytes_to_chksum(&G.chksum_out, buf, cnt);
544 static void f_read(void* buf, int cnt)
547 add_bytes_to_chksum(&G.chksum_in, buf, cnt);
550 static int f_read8(void)
557 static void f_write8(uint8_t v)
562 static unsigned f_read16(void)
569 static void f_write16(uint16_t v)
575 static uint32_t f_read32(void)
582 static void f_write32(uint32_t v)
588 /**********************************************************************/
589 static int lzo_get_method(header_t *h)
592 if (h->method == M_LZO1X_1) {
595 } else if (h->method == M_LZO1X_1_15) {
598 } else if (h->method == M_LZO1X_999) {
602 return -1; /* not a LZO method */
604 /* check compression level */
605 if (h->level < 1 || h->level > 9)
611 /**********************************************************************/
612 #define LZO_BLOCK_SIZE (256 * 1024l)
613 #define MAX_BLOCK_SIZE (64 * 1024l * 1024l) /* DO NOT CHANGE */
615 /* LZO may expand uncompressible data by a small amount */
616 #define MAX_COMPRESSED_SIZE(x) ((x) + (x) / 16 + 64 + 3)
618 /**********************************************************************/
620 /**********************************************************************/
621 static NOINLINE smallint lzo_compress(const header_t *h)
623 unsigned block_size = LZO_BLOCK_SIZE;
624 int r = 0; /* LZO_E_OK */
625 uint8_t *const b1 = xzalloc(block_size);
626 uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size));
627 unsigned src_len = 0, dst_len = 0;
628 uint32_t d_adler32 = ADLER32_INIT_VALUE;
629 uint32_t d_crc32 = CRC32_INIT_VALUE;
632 uint8_t *wrk_mem = NULL;
634 if (h->method == M_LZO1X_1)
635 wrk_mem = xzalloc(LZO1X_1_MEM_COMPRESS);
636 else if (h->method == M_LZO1X_1_15)
637 wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
638 else if (h->method == M_LZO1X_999)
639 wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS);
643 l = full_read(0, b1, block_size);
644 src_len = (l > 0 ? l : 0);
646 /* write uncompressed block size */
649 /* exit if last block */
653 /* compute checksum of uncompressed block */
654 if (h->flags & F_ADLER32_D)
655 d_adler32 = lzo_adler32(ADLER32_INIT_VALUE, b1, src_len);
656 if (h->flags & F_CRC32_D)
657 d_crc32 = lzo_crc32(CRC32_INIT_VALUE, b1, src_len);
660 if (h->method == M_LZO1X_1)
661 r = lzo1x_1_compress(b1, src_len, b2, &dst_len, wrk_mem);
662 else if (h->method == M_LZO1X_1_15)
663 r = lzo1x_1_15_compress(b1, src_len, b2, &dst_len, wrk_mem);
664 #if ENABLE_LZOP_COMPR_HIGH
665 else if (h->method == M_LZO1X_999)
666 r = lzo1x_999_compress_level(b1, src_len, b2, &dst_len,
670 bb_error_msg_and_die("internal error");
672 if (r != 0) /* not LZO_E_OK */
673 bb_error_msg_and_die("internal error - compression failed");
675 /* write compressed block size */
676 if (dst_len < src_len) {
678 if (h->method == M_LZO1X_999) {
679 unsigned new_len = src_len;
680 r = lzo1x_optimize(b2, dst_len, b1, &new_len, NULL);
681 if (r != 0 /*LZO_E_OK*/ || new_len != src_len)
682 bb_error_msg_and_die("internal error - optimization failed");
686 /* data actually expanded => store data uncompressed */
690 /* write checksum of uncompressed block */
691 if (h->flags & F_ADLER32_D)
693 if (h->flags & F_CRC32_D)
696 if (dst_len < src_len) {
697 /* write checksum of compressed block */
698 if (h->flags & F_ADLER32_C)
699 write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
700 if (h->flags & F_CRC32_C)
701 write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
702 /* write compressed block data */
703 xwrite(1, b2, dst_len);
705 /* write uncompressed block data */
706 xwrite(1, b1, src_len);
716 static FAST_FUNC void lzo_check(
718 uint8_t* buf, unsigned len,
719 uint32_t FAST_FUNC (*fn)(uint32_t, const uint8_t*, unsigned),
722 /* This function, by having the same order of parameters
723 * as fn, and by being marked FAST_FUNC (same as fn),
724 * saves a dozen bytes of code.
726 uint32_t c = fn(init, buf, len);
728 bb_error_msg_and_die("checksum error");
731 /**********************************************************************/
733 /**********************************************************************/
734 static NOINLINE smallint lzo_decompress(const header_t *h)
736 unsigned block_size = LZO_BLOCK_SIZE;
738 uint32_t src_len, dst_len;
739 uint32_t c_adler32 = ADLER32_INIT_VALUE;
740 uint32_t d_adler32 = ADLER32_INIT_VALUE;
741 uint32_t c_crc32 = CRC32_INIT_VALUE, d_crc32 = CRC32_INIT_VALUE;
744 uint32_t mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
750 /* read uncompressed block size */
753 /* exit if last block */
757 /* error if split file */
758 if (dst_len == 0xffffffffL)
759 /* should not happen - not yet implemented */
760 bb_error_msg_and_die("this file is a split lzop file");
762 if (dst_len > MAX_BLOCK_SIZE)
763 bb_error_msg_and_die("corrupted data");
765 /* read compressed block size */
767 if (src_len <= 0 || src_len > dst_len)
768 bb_error_msg_and_die("corrupted data");
770 if (dst_len > block_size) {
775 block_size = dst_len;
776 mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
779 /* read checksum of uncompressed block */
780 if (h->flags & F_ADLER32_D)
781 d_adler32 = read32();
782 if (h->flags & F_CRC32_D)
785 /* read checksum of compressed block */
786 if (src_len < dst_len) {
787 if (h->flags & F_ADLER32_C)
788 c_adler32 = read32();
789 if (h->flags & F_CRC32_C)
794 b2 = xzalloc(mcs_block_size);
795 /* read the block into the end of our buffer */
796 b1 = b2 + mcs_block_size - src_len;
797 xread(0, b1, src_len);
799 if (src_len < dst_len) {
800 unsigned d = dst_len;
802 if (!(option_mask32 & OPT_F)) {
803 /* verify checksum of compressed block */
804 if (h->flags & F_ADLER32_C)
805 lzo_check(ADLER32_INIT_VALUE,
807 lzo_adler32, c_adler32);
808 if (h->flags & F_CRC32_C)
809 lzo_check(CRC32_INIT_VALUE,
815 // if (option_mask32 & OPT_F)
816 // r = lzo1x_decompress(b1, src_len, b2, &d, NULL);
818 r = lzo1x_decompress_safe(b1, src_len, b2, &d, NULL);
820 if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
821 bb_error_msg_and_die("corrupted data");
825 /* "stored" block => no decompression */
829 if (!(option_mask32 & OPT_F)) {
830 /* verify checksum of uncompressed block */
831 if (h->flags & F_ADLER32_D)
832 lzo_check(ADLER32_INIT_VALUE,
834 lzo_adler32, d_adler32);
835 if (h->flags & F_CRC32_D)
836 lzo_check(CRC32_INIT_VALUE,
841 /* write uncompressed block data */
842 xwrite(1, dst, dst_len);
849 /**********************************************************************/
850 // lzop file signature (shamelessly borrowed from PNG)
851 /**********************************************************************/
853 * The first nine bytes of a lzop file always contain the following values:
856 * --- --- --- --- --- --- --- --- ---
857 * (hex) 89 4c 5a 4f 00 0d 0a 1a 0a
858 * (decimal) 137 76 90 79 0 13 10 26 10
859 * (C notation - ASCII) \211 L Z O \0 \r \n \032 \n
862 /* (vda) comparison with lzop v1.02rc1 ("lzop -1 <FILE" cmd):
863 * Only slight differences in header:
864 * -00000000 89 4c 5a 4f 00 0d 0a 1a 0a 10 20 20 20 09 40 02
865 * +00000000 89 4c 5a 4f 00 0d 0a 1a 0a 10 10 20 30 09 40 02
867 * version lib_version
868 * -00000010 01 03 00 00 0d 00 00 81 a4 49 f7 a6 3f 00 00 00
869 * +00000010 01 03 00 00 01 00 00 00 00 00 00 00 00 00 00 00
870 * ^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^
872 * -00000020 00 00 2d 67 04 17 00 04 00 00 00 03 ed ec 9d 6d
873 * +00000020 00 00 10 5f 00 c1 00 04 00 00 00 03 ed ec 9d 6d
876 * The rest is identical.
878 static const unsigned char lzop_magic[9] = {
879 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
882 /* This coding is derived from Alexander Lehmann's pngcheck code. */
883 static void check_magic(void)
885 unsigned char magic[sizeof(lzop_magic)];
886 xread(0, magic, sizeof(magic));
887 if (memcmp(magic, lzop_magic, sizeof(lzop_magic)) != 0)
888 bb_error_msg_and_die("bad magic number");
891 /**********************************************************************/
893 /**********************************************************************/
894 static void write_header(const header_t *h)
898 xwrite(1, lzop_magic, sizeof(lzop_magic));
900 init_chksum(&G.chksum_out);
902 f_write16(h->version);
903 f_write16(h->lib_version);
904 f_write16(h->version_needed_to_extract);
910 f_write32(h->gmtdiff);
912 l = (int) strlen(h->name);
917 f_write32(chksum_getresult(&G.chksum_out, h));
920 static int read_header(header_t *h)
926 memset(h, 0, sizeof(*h));
927 h->version_needed_to_extract = 0x0900; /* first lzop version */
930 init_chksum(&G.chksum_in);
932 h->version = f_read16();
933 if (h->version < 0x0900)
935 h->lib_version = f_read16();
936 if (h->version >= 0x0940) {
937 h->version_needed_to_extract = f_read16();
938 if (h->version_needed_to_extract > LZOP_VERSION)
940 if (h->version_needed_to_extract < 0x0900)
943 h->method = f_read8();
944 if (h->version >= 0x0940)
945 h->level = f_read8();
946 h->flags = f_read32();
947 if (h->flags & F_H_FILTER)
948 return 16; /* filter not supported */
949 h->mode = f_read32();
950 h->mtime = f_read32();
951 if (h->version >= 0x0940)
952 h->gmtdiff = f_read32();
959 checksum = chksum_getresult(&G.chksum_in, h);
960 h->header_checksum = f_read32();
961 if (h->header_checksum != checksum)
966 r = lzo_get_method(h);
970 /* check reserved flags */
971 if (h->flags & F_RESERVED)
974 /* skip extra field [not used yet] */
975 if (h->flags & F_H_EXTRA_FIELD) {
978 /* note: the checksum also covers the length */
979 init_chksum(&G.chksum_in);
980 h->extra_field_len = f_read32();
981 for (k = 0; k < h->extra_field_len; k++)
983 checksum = chksum_getresult(&G.chksum_in, h);
984 h->extra_field_checksum = f_read32();
985 if (h->extra_field_checksum != checksum)
992 static void p_header(header_t *h)
999 bb_error_msg_and_die("header_error %d", r);
1002 /**********************************************************************/
1004 /**********************************************************************/
1005 static void lzo_set_method(header_t *h)
1009 if (option_mask32 & OPT_1) {
1010 h->method = M_LZO1X_1_15;
1011 } else if (option_mask32 & OPT_789) {
1012 #if ENABLE_LZOP_COMPR_HIGH
1013 h->method = M_LZO1X_999;
1014 if (option_mask32 & OPT_7)
1016 else if (option_mask32 & OPT_8)
1021 bb_error_msg_and_die("high compression not compiled in");
1023 } else { /* levels 2..6 or none (defaults to level 3) */
1024 h->method = M_LZO1X_1;
1025 level = 5; /* levels 2-6 are actually the same */
1031 static smallint do_lzo_compress(void)
1036 memset(h, 0, sizeof(*h));
1040 h->version = (LZOP_VERSION & 0xffff);
1041 h->version_needed_to_extract = 0x0940;
1042 h->lib_version = lzo_version() & 0xffff;
1044 h->flags = (F_OS & F_OS_MASK) | (F_CS & F_CS_MASK);
1046 if (!(option_mask32 & OPT_F) || h->method == M_LZO1X_999) {
1047 h->flags |= F_ADLER32_D;
1048 if (option_mask32 & OPT_C)
1049 h->flags |= F_ADLER32_C;
1052 return lzo_compress(h);
1056 /**********************************************************************/
1058 /**********************************************************************/
1059 static smallint do_lzo_decompress(void)
1065 return lzo_decompress(&header);
1068 static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_ext UNUSED_PARAM)
1070 if (option_mask32 & OPT_DECOMPRESS) {
1071 char *extension = strrchr(filename, '.');
1072 if (!extension || strcmp(extension + 1, "lzo") != 0)
1073 return xasprintf("%s.out", filename);
1077 return xasprintf("%s.lzo", filename);
1080 static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(unpack_info_t *info UNUSED_PARAM)
1082 if (option_mask32 & OPT_DECOMPRESS)
1083 return do_lzo_decompress();
1084 return do_lzo_compress();
1087 int lzop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1088 int lzop_main(int argc UNUSED_PARAM, char **argv)
1090 getopt32(argv, OPTION_STRING);
1093 if (applet_name[4] == 'c')
1094 option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
1096 if (applet_name[0] == 'u')
1097 option_mask32 |= OPT_DECOMPRESS;
1099 global_crc32_table = crc32_filltable(NULL, 0);
1100 return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);