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 //kbuild:lib-$(CONFIG_LZOP) += lzop.o
30 //usage:#define lzop_trivial_usage
31 //usage: "[-cfvd123456789CF] [FILE]..."
32 //usage:#define lzop_full_usage "\n\n"
33 //usage: " -1..9 Compression level"
34 //usage: "\n -d Decompress"
35 //usage: "\n -c Write to stdout"
36 //usage: "\n -f Force"
37 //usage: "\n -v Verbose"
38 //usage: "\n -F Don't store or verify checksum"
39 //usage: "\n -C Also write checksum of compressed block"
41 //usage:#define lzopcat_trivial_usage
42 //usage: "[-vCF] [FILE]..."
43 //usage:#define lzopcat_full_usage "\n\n"
44 //usage: " -v Verbose"
45 //usage: "\n -F Don't store or verify checksum"
47 //usage:#define unlzop_trivial_usage
48 //usage: "[-cfvCF] [FILE]..."
49 //usage:#define unlzop_full_usage "\n\n"
50 //usage: " -c Write to stdout"
51 //usage: "\n -f Force"
52 //usage: "\n -v Verbose"
53 //usage: "\n -F Don't store or verify checksum"
56 #include "bb_archive.h"
57 #include "liblzo_interface.h"
59 /* lzo-2.03/src/lzo_ptr.h */
60 #define pd(a,b) ((unsigned)((a)-(b)))
62 #define lzo_version() LZO_VERSION
63 #define lzo_sizeof_dict_t (sizeof(uint8_t*))
65 /* lzo-2.03/include/lzo/lzo1x.h */
66 #define LZO1X_1_MEM_COMPRESS (16384 * lzo_sizeof_dict_t)
67 #define LZO1X_1_15_MEM_COMPRESS (32768 * lzo_sizeof_dict_t)
68 #define LZO1X_999_MEM_COMPRESS (14 * 16384 * sizeof(short))
70 /* lzo-2.03/src/lzo1x_oo.c */
71 #define NO_LIT UINT_MAX
73 /**********************************************************************/
74 static void copy2(uint8_t* ip, const uint8_t* m_pos, unsigned off)
83 static void copy3(uint8_t* ip, const uint8_t* m_pos, unsigned off)
87 ip[2] = ip[1] = m_pos[0];
99 /**********************************************************************/
100 // optimize a block of data.
101 /**********************************************************************/
102 #define TEST_IP (ip < ip_end)
103 #define TEST_OP (op <= op_end)
105 static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
106 uint8_t *out, unsigned *out_len,
107 void* wrkmem UNUSED_PARAM)
113 uint8_t* const ip_end = in + in_len;
114 uint8_t* const op_end = out + *out_len;
115 uint8_t* litp = NULL;
117 unsigned next_lit = NO_LIT;
119 unsigned long o_m1_a = 0, o_m1_b = 0, o_m2 = 0, o_m3_a = 0, o_m3_b = 0;
121 // LZO_UNUSED(wrkmem);
132 goto first_literal_run;
135 while (TEST_IP && TEST_OP) {
154 do *op++ = *ip++; while (--t > 0);
161 m_pos = op - 1 - 0x800;
163 m_pos = op - 1 - 0x400;
176 if (t < 16) { /* a M1 match */
185 /* test if a match follows */
186 if (nl == 0 && lit == 1 && ip[0] >= 16) {
188 /* adjust length of previous short run */
190 *litp = (unsigned char)((*litp & ~3) | lit);
191 /* copy over the 2 literals that replace the match */
192 copy2(ip-2, m_pos, pd(op, m_pos));
195 /* test if a literal run follows */
200 && (lit + 2 + ip[0] < 16)
203 /* remove short run */
205 /* copy over the 2 literals that replace the match */
206 copy2(ip-3+1, m_pos, pd(op, m_pos));
207 /* move literals 1 byte ahead */
210 memmove(litp+1, litp, lit);
211 /* insert new length of long literal run */
213 *litp = (unsigned char)(lit - 3);
218 goto copy_literal_run;
225 if (t >= 64) { /* a M2 match */
228 m_pos -= (t >> 2) & 7;
232 m_pos -= (t >> 2) & 3;
240 /* test if in beetween two long literal runs */
241 if (t == 1 && lit > 3 && nl == 0
242 && ip[0] < 16 && ip[0] != 0 && (lit + 3 + ip[0] < 16)
245 /* copy over the 3 literals that replace the match */
246 copy3(ip-1-2, m_pos, pd(op, m_pos));
247 /* set new length of previous literal run */
249 *litp = (unsigned char)(lit - 3);
254 goto copy_literal_run;
257 if (t >= 32) { /* a M3 match */
268 } else { /* a M4 match */
270 m_pos -= (t & 8) << 11;
288 /* test if in beetween two matches */
289 if (t == 1 && lit == 0 && nl == 0 && ip[0] >= 16) {
291 /* make a previous short run */
293 *litp = (unsigned char)((*litp & ~3) | lit);
294 /* copy over the 3 literals that replace the match */
295 copy3(ip-3, m_pos, pd(op, m_pos));
298 /* test if a literal run follows */
299 else if (t == 1 && lit <= 3 && nl == 0
300 && ip[0] < 16 && ip[0] != 0 && (lit + 3 + ip[0] < 16)
303 /* remove short run */
305 /* copy over the 3 literals that replace the match */
306 copy3(ip-4+1, m_pos, pd(op, m_pos));
307 /* move literals 1 byte ahead */
310 memmove(litp+1,litp,lit);
311 /* insert new length of long literal run */
313 *litp = (unsigned char)(lit - 3);
319 goto copy_literal_run;
325 do *op++ = *m_pos++; while (--t > 0);
329 if (next_lit == NO_LIT) {
341 do *op++ = *ip++; while (--t > 0);
343 } while (TEST_IP && TEST_OP);
346 /* no EOF code was found */
347 *out_len = pd(op, out);
348 return LZO_E_EOF_NOT_FOUND;
351 // LZO_UNUSED(o_m1_a); LZO_UNUSED(o_m1_b); LZO_UNUSED(o_m2);
352 // LZO_UNUSED(o_m3_a); LZO_UNUSED(o_m3_b);
353 *out_len = pd(op, out);
354 return (ip == ip_end ? LZO_E_OK :
355 (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
358 /**********************************************************************/
359 #define F_OS F_OS_UNIX
360 #define F_CS F_CS_NATIVE
362 /**********************************************************************/
363 #define ADLER32_INIT_VALUE 1
364 #define CRC32_INIT_VALUE 0
366 /**********************************************************************/
373 /**********************************************************************/
375 #define F_ADLER32_D 0x00000001L
376 #define F_ADLER32_C 0x00000002L
377 #define F_H_EXTRA_FIELD 0x00000040L
378 #define F_H_GMTDIFF 0x00000080L
379 #define F_CRC32_D 0x00000100L
380 #define F_CRC32_C 0x00000200L
381 #define F_H_FILTER 0x00000800L
382 #define F_H_CRC32 0x00001000L
383 #define F_MASK 0x00003FFFL
385 /* operating system & file system that created the file [mostly unused] */
386 #define F_OS_UNIX 0x03000000L
387 #define F_OS_SHIFT 24
388 #define F_OS_MASK 0xff000000L
390 /* character set for file name encoding [mostly unused] */
391 #define F_CS_NATIVE 0x00000000L
392 #define F_CS_SHIFT 20
393 #define F_CS_MASK 0x00f00000L
395 /* these bits must be zero */
396 #define F_RESERVED ((F_MASK | F_OS_MASK | F_CS_MASK) ^ 0xffffffffL)
398 typedef struct chksum_t {
403 typedef struct header_t {
405 unsigned lib_version;
406 unsigned version_needed_to_extract;
411 uint32_t header_checksum;
413 uint32_t extra_field_len;
414 uint32_t extra_field_checksum;
416 unsigned char method;
424 /*const uint32_t *lzo_crc32_table;*/
428 #define G (*(struct globals*)&bb_common_bufsiz1)
429 #define INIT_G() do { } while (0)
430 //#define G (*ptr_to_globals)
431 //#define INIT_G() do {
432 // SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
436 /**********************************************************************/
437 #define LZOP_VERSION 0x1010
438 //#define LZOP_VERSION_STRING "1.01"
439 //#define LZOP_VERSION_DATE "Apr 27th 2003"
441 #define OPTION_STRING "cfvqdt123456789CF"
443 /* Note: must be kept in sync with archival/bbunzip.c */
445 OPT_STDOUT = (1 << 0),
446 OPT_FORCE = (1 << 1),
447 OPT_VERBOSE = (1 << 2),
448 OPT_QUIET = (1 << 3),
449 OPT_DECOMPRESS = (1 << 4),
464 /**********************************************************************/
466 // adapted from free code by Mark Adler <madler@alumni.caltech.edu>
467 // see http://www.zlib.org/
468 /**********************************************************************/
469 static FAST_FUNC uint32_t
470 lzo_adler32(uint32_t adler, const uint8_t* buf, unsigned len)
473 LZO_BASE = 65521, /* largest prime smaller than 65536 */
474 /* NMAX is the largest n such that
475 * 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
478 uint32_t s1 = adler & 0xffff;
479 uint32_t s2 = (adler >> 16) & 0xffff;
486 k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
495 return (s2 << 16) | s1;
498 static FAST_FUNC uint32_t
499 lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
501 //if (buf == NULL) - impossible
504 return ~crc32_block_endian0(~c, buf, len, global_crc32_table);
507 /**********************************************************************/
508 static void init_chksum(chksum_t *ct)
510 ct->f_adler32 = ADLER32_INIT_VALUE;
511 ct->f_crc32 = CRC32_INIT_VALUE;
514 static void add_bytes_to_chksum(chksum_t *ct, const void* buf, int cnt)
516 /* We need to handle the two checksums at once, because at the
517 * beginning of the header, we don't know yet which one we'll
519 ct->f_adler32 = lzo_adler32(ct->f_adler32, (const uint8_t*)buf, cnt);
520 ct->f_crc32 = lzo_crc32(ct->f_crc32, (const uint8_t*)buf, cnt);
523 static uint32_t chksum_getresult(chksum_t *ct, const header_t *h)
525 return (h->flags & F_H_CRC32) ? ct->f_crc32 : ct->f_adler32;
528 /**********************************************************************/
529 static uint32_t read32(void)
536 static void write32(uint32_t v)
542 static void f_write(const void* buf, int cnt)
545 add_bytes_to_chksum(&G.chksum_out, buf, cnt);
548 static void f_read(void* buf, int cnt)
551 add_bytes_to_chksum(&G.chksum_in, buf, cnt);
554 static int f_read8(void)
561 static void f_write8(uint8_t v)
566 static unsigned f_read16(void)
573 static void f_write16(uint16_t v)
579 static uint32_t f_read32(void)
586 static void f_write32(uint32_t v)
592 /**********************************************************************/
593 static int lzo_get_method(header_t *h)
596 if (h->method == M_LZO1X_1) {
599 } else if (h->method == M_LZO1X_1_15) {
602 } else if (h->method == M_LZO1X_999) {
606 return -1; /* not a LZO method */
608 /* check compression level */
609 if (h->level < 1 || h->level > 9)
615 /**********************************************************************/
616 #define LZO_BLOCK_SIZE (256 * 1024l)
617 #define MAX_BLOCK_SIZE (64 * 1024l * 1024l) /* DO NOT CHANGE */
619 /* LZO may expand uncompressible data by a small amount */
620 #define MAX_COMPRESSED_SIZE(x) ((x) + (x) / 16 + 64 + 3)
622 /**********************************************************************/
624 /**********************************************************************/
625 static NOINLINE smallint lzo_compress(const header_t *h)
627 unsigned block_size = LZO_BLOCK_SIZE;
628 int r = 0; /* LZO_E_OK */
629 uint8_t *const b1 = xzalloc(block_size);
630 uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size));
631 unsigned src_len = 0, dst_len = 0;
632 uint32_t d_adler32 = ADLER32_INIT_VALUE;
633 uint32_t d_crc32 = CRC32_INIT_VALUE;
636 uint8_t *wrk_mem = NULL;
638 if (h->method == M_LZO1X_1)
639 wrk_mem = xzalloc(LZO1X_1_MEM_COMPRESS);
640 else if (h->method == M_LZO1X_1_15)
641 wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
642 else if (h->method == M_LZO1X_999)
643 wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS);
647 l = full_read(0, b1, block_size);
648 src_len = (l > 0 ? l : 0);
650 /* write uncompressed block size */
653 /* exit if last block */
657 /* compute checksum of uncompressed block */
658 if (h->flags & F_ADLER32_D)
659 d_adler32 = lzo_adler32(ADLER32_INIT_VALUE, b1, src_len);
660 if (h->flags & F_CRC32_D)
661 d_crc32 = lzo_crc32(CRC32_INIT_VALUE, b1, src_len);
664 if (h->method == M_LZO1X_1)
665 r = lzo1x_1_compress(b1, src_len, b2, &dst_len, wrk_mem);
666 else if (h->method == M_LZO1X_1_15)
667 r = lzo1x_1_15_compress(b1, src_len, b2, &dst_len, wrk_mem);
668 #if ENABLE_LZOP_COMPR_HIGH
669 else if (h->method == M_LZO1X_999)
670 r = lzo1x_999_compress_level(b1, src_len, b2, &dst_len,
674 bb_error_msg_and_die("internal error");
676 if (r != 0) /* not LZO_E_OK */
677 bb_error_msg_and_die("internal error - compression failed");
679 /* write compressed block size */
680 if (dst_len < src_len) {
682 if (h->method == M_LZO1X_999) {
683 unsigned new_len = src_len;
684 r = lzo1x_optimize(b2, dst_len, b1, &new_len, NULL);
685 if (r != 0 /*LZO_E_OK*/ || new_len != src_len)
686 bb_error_msg_and_die("internal error - optimization failed");
690 /* data actually expanded => store data uncompressed */
694 /* write checksum of uncompressed block */
695 if (h->flags & F_ADLER32_D)
697 if (h->flags & F_CRC32_D)
700 if (dst_len < src_len) {
701 /* write checksum of compressed block */
702 if (h->flags & F_ADLER32_C)
703 write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
704 if (h->flags & F_CRC32_C)
705 write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
706 /* write compressed block data */
707 xwrite(1, b2, dst_len);
709 /* write uncompressed block data */
710 xwrite(1, b1, src_len);
720 static FAST_FUNC void lzo_check(
722 uint8_t* buf, unsigned len,
723 uint32_t FAST_FUNC (*fn)(uint32_t, const uint8_t*, unsigned),
726 /* This function, by having the same order of parameters
727 * as fn, and by being marked FAST_FUNC (same as fn),
728 * saves a dozen bytes of code.
730 uint32_t c = fn(init, buf, len);
732 bb_error_msg_and_die("checksum error");
735 /**********************************************************************/
737 /**********************************************************************/
738 static NOINLINE smallint lzo_decompress(const header_t *h)
740 unsigned block_size = LZO_BLOCK_SIZE;
742 uint32_t src_len, dst_len;
743 uint32_t c_adler32 = ADLER32_INIT_VALUE;
744 uint32_t d_adler32 = ADLER32_INIT_VALUE;
745 uint32_t c_crc32 = CRC32_INIT_VALUE, d_crc32 = CRC32_INIT_VALUE;
748 uint32_t mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
754 /* read uncompressed block size */
757 /* exit if last block */
761 /* error if split file */
762 if (dst_len == 0xffffffffL)
763 /* should not happen - not yet implemented */
764 bb_error_msg_and_die("this file is a split lzop file");
766 if (dst_len > MAX_BLOCK_SIZE)
767 bb_error_msg_and_die("corrupted data");
769 /* read compressed block size */
771 if (src_len <= 0 || src_len > dst_len)
772 bb_error_msg_and_die("corrupted data");
774 if (dst_len > block_size) {
779 block_size = dst_len;
780 mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
783 /* read checksum of uncompressed block */
784 if (h->flags & F_ADLER32_D)
785 d_adler32 = read32();
786 if (h->flags & F_CRC32_D)
789 /* read checksum of compressed block */
790 if (src_len < dst_len) {
791 if (h->flags & F_ADLER32_C)
792 c_adler32 = read32();
793 if (h->flags & F_CRC32_C)
798 b2 = xzalloc(mcs_block_size);
799 /* read the block into the end of our buffer */
800 b1 = b2 + mcs_block_size - src_len;
801 xread(0, b1, src_len);
803 if (src_len < dst_len) {
804 unsigned d = dst_len;
806 if (!(option_mask32 & OPT_F)) {
807 /* verify checksum of compressed block */
808 if (h->flags & F_ADLER32_C)
809 lzo_check(ADLER32_INIT_VALUE,
811 lzo_adler32, c_adler32);
812 if (h->flags & F_CRC32_C)
813 lzo_check(CRC32_INIT_VALUE,
819 // if (option_mask32 & OPT_F)
820 // r = lzo1x_decompress(b1, src_len, b2, &d, NULL);
822 r = lzo1x_decompress_safe(b1, src_len, b2, &d, NULL);
824 if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
825 bb_error_msg_and_die("corrupted data");
829 /* "stored" block => no decompression */
833 if (!(option_mask32 & OPT_F)) {
834 /* verify checksum of uncompressed block */
835 if (h->flags & F_ADLER32_D)
836 lzo_check(ADLER32_INIT_VALUE,
838 lzo_adler32, d_adler32);
839 if (h->flags & F_CRC32_D)
840 lzo_check(CRC32_INIT_VALUE,
845 /* write uncompressed block data */
846 xwrite(1, dst, dst_len);
853 /**********************************************************************/
854 // lzop file signature (shamelessly borrowed from PNG)
855 /**********************************************************************/
857 * The first nine bytes of a lzop file always contain the following values:
860 * --- --- --- --- --- --- --- --- ---
861 * (hex) 89 4c 5a 4f 00 0d 0a 1a 0a
862 * (decimal) 137 76 90 79 0 13 10 26 10
863 * (C notation - ASCII) \211 L Z O \0 \r \n \032 \n
866 /* (vda) comparison with lzop v1.02rc1 ("lzop -1 <FILE" cmd):
867 * Only slight differences in header:
868 * -00000000 89 4c 5a 4f 00 0d 0a 1a 0a 10 20 20 20 09 40 02
869 * +00000000 89 4c 5a 4f 00 0d 0a 1a 0a 10 10 20 30 09 40 02
871 * version lib_version
872 * -00000010 01 03 00 00 0d 00 00 81 a4 49 f7 a6 3f 00 00 00
873 * +00000010 01 03 00 00 01 00 00 00 00 00 00 00 00 00 00 00
874 * ^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^
876 * -00000020 00 00 2d 67 04 17 00 04 00 00 00 03 ed ec 9d 6d
877 * +00000020 00 00 10 5f 00 c1 00 04 00 00 00 03 ed ec 9d 6d
880 * The rest is identical.
882 static const unsigned char lzop_magic[9] = {
883 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
886 /* This coding is derived from Alexander Lehmann's pngcheck code. */
887 static void check_magic(void)
889 unsigned char magic[sizeof(lzop_magic)];
890 xread(0, magic, sizeof(magic));
891 if (memcmp(magic, lzop_magic, sizeof(lzop_magic)) != 0)
892 bb_error_msg_and_die("bad magic number");
895 /**********************************************************************/
897 /**********************************************************************/
898 static void write_header(const header_t *h)
902 xwrite(1, lzop_magic, sizeof(lzop_magic));
904 init_chksum(&G.chksum_out);
906 f_write16(h->version);
907 f_write16(h->lib_version);
908 f_write16(h->version_needed_to_extract);
914 f_write32(h->gmtdiff);
916 l = (int) strlen(h->name);
921 f_write32(chksum_getresult(&G.chksum_out, h));
924 static int read_header(header_t *h)
930 memset(h, 0, sizeof(*h));
931 h->version_needed_to_extract = 0x0900; /* first lzop version */
934 init_chksum(&G.chksum_in);
936 h->version = f_read16();
937 if (h->version < 0x0900)
939 h->lib_version = f_read16();
940 if (h->version >= 0x0940) {
941 h->version_needed_to_extract = f_read16();
942 if (h->version_needed_to_extract > LZOP_VERSION)
944 if (h->version_needed_to_extract < 0x0900)
947 h->method = f_read8();
948 if (h->version >= 0x0940)
949 h->level = f_read8();
950 h->flags = f_read32();
951 if (h->flags & F_H_FILTER)
952 return 16; /* filter not supported */
953 h->mode = f_read32();
954 h->mtime = f_read32();
955 if (h->version >= 0x0940)
956 h->gmtdiff = f_read32();
963 checksum = chksum_getresult(&G.chksum_in, h);
964 h->header_checksum = f_read32();
965 if (h->header_checksum != checksum)
970 r = lzo_get_method(h);
974 /* check reserved flags */
975 if (h->flags & F_RESERVED)
978 /* skip extra field [not used yet] */
979 if (h->flags & F_H_EXTRA_FIELD) {
982 /* note: the checksum also covers the length */
983 init_chksum(&G.chksum_in);
984 h->extra_field_len = f_read32();
985 for (k = 0; k < h->extra_field_len; k++)
987 checksum = chksum_getresult(&G.chksum_in, h);
988 h->extra_field_checksum = f_read32();
989 if (h->extra_field_checksum != checksum)
996 static void p_header(header_t *h)
1003 bb_error_msg_and_die("header_error %d", r);
1006 /**********************************************************************/
1008 /**********************************************************************/
1009 static void lzo_set_method(header_t *h)
1013 if (option_mask32 & OPT_1) {
1014 h->method = M_LZO1X_1_15;
1015 } else if (option_mask32 & OPT_789) {
1016 #if ENABLE_LZOP_COMPR_HIGH
1017 h->method = M_LZO1X_999;
1018 if (option_mask32 & OPT_7)
1020 else if (option_mask32 & OPT_8)
1025 bb_error_msg_and_die("high compression not compiled in");
1027 } else { /* levels 2..6 or none (defaults to level 3) */
1028 h->method = M_LZO1X_1;
1029 level = 5; /* levels 2-6 are actually the same */
1035 static smallint do_lzo_compress(void)
1040 memset(h, 0, sizeof(*h));
1044 h->version = (LZOP_VERSION & 0xffff);
1045 h->version_needed_to_extract = 0x0940;
1046 h->lib_version = lzo_version() & 0xffff;
1048 h->flags = (F_OS & F_OS_MASK) | (F_CS & F_CS_MASK);
1050 if (!(option_mask32 & OPT_F) || h->method == M_LZO1X_999) {
1051 h->flags |= F_ADLER32_D;
1052 if (option_mask32 & OPT_C)
1053 h->flags |= F_ADLER32_C;
1056 return lzo_compress(h);
1060 /**********************************************************************/
1062 /**********************************************************************/
1063 static smallint do_lzo_decompress(void)
1069 return lzo_decompress(&header);
1072 static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_ext UNUSED_PARAM)
1074 if (option_mask32 & OPT_DECOMPRESS) {
1075 char *extension = strrchr(filename, '.');
1076 if (!extension || strcmp(extension + 1, "lzo") != 0)
1077 return xasprintf("%s.out", filename);
1081 return xasprintf("%s.lzo", filename);
1084 static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
1086 if (option_mask32 & OPT_DECOMPRESS)
1087 return do_lzo_decompress();
1088 return do_lzo_compress();
1091 int lzop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1092 int lzop_main(int argc UNUSED_PARAM, char **argv)
1094 getopt32(argv, OPTION_STRING);
1097 if (applet_name[4] == 'c')
1098 option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
1100 if (applet_name[4] == 'o')
1101 option_mask32 |= OPT_DECOMPRESS;
1103 global_crc32_table = crc32_filltable(NULL, 0);
1104 return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);