Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 1 | /* |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 2 | * compression handling for cbfstool |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 3 | * |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 4 | * 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. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 10 | * |
| 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 Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include "common.h" |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 28 | |
Stefan Reinauer | aa3f7ba | 2013-03-28 16:51:45 -0700 | [diff] [blame] | 29 | static void lzma_compress(char *in, int in_len, char *out, int *out_len) |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 30 | { |
| 31 | do_lzma_compress(in, in_len, out, out_len); |
| 32 | } |
| 33 | |
Stefan Reinauer | aa3f7ba | 2013-03-28 16:51:45 -0700 | [diff] [blame] | 34 | static void none_compress(char *in, int in_len, char *out, int *out_len) |
Ronald G. Minnich | 5d01ec0 | 2009-03-31 11:57:36 +0000 | [diff] [blame] | 35 | { |
| 36 | memcpy(out, in, in_len); |
| 37 | *out_len = in_len; |
| 38 | } |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 39 | |
| 40 | comp_func_ptr compression_function(comp_algo algo) |
| 41 | { |
| 42 | comp_func_ptr compress; |
| 43 | switch (algo) { |
| 44 | case CBFS_COMPRESS_NONE: |
| 45 | compress = none_compress; |
| 46 | break; |
| 47 | case CBFS_COMPRESS_LZMA: |
| 48 | compress = lzma_compress; |
| 49 | break; |
| 50 | default: |
Hung-Te Lin | 4d87d4e | 2013-01-28 14:39:43 +0800 | [diff] [blame] | 51 | ERROR("Unknown compression algorithm %d!\n", algo); |
Patrick Georgi | b7b56dd8 | 2009-09-14 13:29:27 +0000 | [diff] [blame] | 52 | return NULL; |
| 53 | } |
| 54 | return compress; |
| 55 | } |