blob: 9f865fb3274f80293edae908512a7418cb0442ae [file] [log] [blame]
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00001/*
Patrick Georgib7b56dd82009-09-14 13:29:27 +00002 * compression handling for cbfstool
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +00003 *
Patrick Georgib7b56dd82009-09-14 13:29:27 +00004 * Copyright (C) 2009 coresystems GmbH
5 * written by Patrick Georgi <patrick.georgi@coresystems.de>
6 *
7 * Adapted from code
8 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>, released
9 * under identical license terms
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
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.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
23 */
24
25#include <string.h>
Patrick Georgib7b56dd82009-09-14 13:29:27 +000026#include <stdio.h>
27#include "common.h"
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000028
Gabe Blackdbd006b2014-02-20 23:38:49 -080029static int lzma_compress(char *in, int in_len, char *out, int *out_len)
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000030{
Gabe Blackdbd006b2014-02-20 23:38:49 -080031 return do_lzma_compress(in, in_len, out, out_len);
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000032}
33
Gabe Blackdbd006b2014-02-20 23:38:49 -080034static int none_compress(char *in, int in_len, char *out, int *out_len)
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000035{
36 memcpy(out, in, in_len);
37 *out_len = in_len;
Gabe Blackdbd006b2014-02-20 23:38:49 -080038 return 0;
Ronald G. Minnich5d01ec02009-03-31 11:57:36 +000039}
Patrick Georgib7b56dd82009-09-14 13:29:27 +000040
Sol Boucher6310ccc2015-05-07 21:12:28 -070041comp_func_ptr compression_function(enum comp_algo algo)
Patrick Georgib7b56dd82009-09-14 13:29:27 +000042{
43 comp_func_ptr compress;
44 switch (algo) {
45 case CBFS_COMPRESS_NONE:
46 compress = none_compress;
47 break;
48 case CBFS_COMPRESS_LZMA:
49 compress = lzma_compress;
50 break;
51 default:
Hung-Te Lin4d87d4e2013-01-28 14:39:43 +080052 ERROR("Unknown compression algorithm %d!\n", algo);
Patrick Georgib7b56dd82009-09-14 13:29:27 +000053 return NULL;
54 }
55 return compress;
56}