cbfstool: have decompress functions provide ouput data size
[coreboot.git] / util / cbfstool / compress.c
blob0313b96898a2054d6e052115d54c5b36f60785af
1 /*
2 * compression handling for cbfstool
4 * Copyright (C) 2009 coresystems GmbH
5 * written by Patrick Georgi <patrick.georgi@coresystems.de>
7 * Adapted from code
8 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>, released
9 * under identical license terms
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.
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; if not, write to the Free Software
22 * Foundation, Inc.
25 #include <string.h>
26 #include <stdio.h>
27 #include "common.h"
29 static int lzma_compress(char *in, int in_len, char *out, int *out_len)
31 return do_lzma_compress(in, in_len, out, out_len);
34 static int lzma_decompress(char *in, int in_len, char *out, unused int out_len,
35 size_t *actual_size)
37 return do_lzma_uncompress(out, out_len, in, in_len, actual_size);
39 static int none_compress(char *in, int in_len, char *out, int *out_len)
41 memcpy(out, in, in_len);
42 *out_len = in_len;
43 return 0;
46 static int none_decompress(char *in, int in_len, char *out, unused int out_len,
47 size_t *actual_size)
49 memcpy(out, in, in_len);
50 if (actual_size != NULL)
51 *actual_size = in_len;
52 return 0;
55 comp_func_ptr compression_function(enum comp_algo algo)
57 comp_func_ptr compress;
58 switch (algo) {
59 case CBFS_COMPRESS_NONE:
60 compress = none_compress;
61 break;
62 case CBFS_COMPRESS_LZMA:
63 compress = lzma_compress;
64 break;
65 default:
66 ERROR("Unknown compression algorithm %d!\n", algo);
67 return NULL;
69 return compress;
72 decomp_func_ptr decompression_function(enum comp_algo algo)
74 decomp_func_ptr decompress;
75 switch (algo) {
76 case CBFS_COMPRESS_NONE:
77 decompress = none_decompress;
78 break;
79 case CBFS_COMPRESS_LZMA:
80 decompress = lzma_decompress;
81 break;
82 default:
83 ERROR("Unknown compression algorithm %d!\n", algo);
84 return NULL;
86 return decompress;