File: compressor.h

package info (click to toggle)
squashfs-tools 1%3A4.2-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,028 kB
  • sloc: ansic: 11,755; makefile: 130
file content (98 lines) | stat: -rw-r--r-- 2,745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *
 * Copyright (c) 2009, 2010, 2011
 * Phillip Lougher <phillip@lougher.demon.co.uk>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * compressor.h
 */

struct compressor {
	int (*init)(void **, int, int);
	int (*compress)(void *, void *, void *, int, int, int *);
	int (*uncompress)(void *, void *, int, int, int *);
	int (*options)(char **, int);
	int (*options_post)(int);
	void *(*dump_options)(int, int *);
	int (*extract_options)(int, void *, int);
	void (*usage)();
	int id;
	char *name;
	int supported;
};

extern struct compressor *lookup_compressor(char *);
extern struct compressor *lookup_compressor_id(int);
extern void display_compressors(char *, char *);
extern void display_compressor_usage(char *);

static inline int compressor_init(struct compressor *comp, void **stream,
	int block_size, int datablock)
{
	if(comp->init == NULL)
		return 0;
	return comp->init(stream, block_size, datablock);
}


static inline int compressor_compress(struct compressor *comp, void *strm,
	void *dest, void *src, int size, int block_size, int *error)
{
	return comp->compress(strm, dest, src, size, block_size, error);
}


static inline int compressor_uncompress(struct compressor *comp, void *dest,
	void *src, int size, int block_size, int *error)
{
	return comp->uncompress(dest, src, size, block_size, error);
}


static inline int compressor_options(struct compressor *comp, char *argv[],
	int argc)
{
	if(comp->options == NULL)
		return -1;

	return comp->options(argv, argc);
}


static inline int compressor_options_post(struct compressor *comp, int block_size)
{
	if(comp->options_post == NULL)
		return 0;
	return comp->options_post(block_size);
}


static inline void *compressor_dump_options(struct compressor *comp,
	int block_size, int *size)
{
	if(comp->dump_options == NULL)
		return NULL;
	return comp->dump_options(block_size, size);
}


static inline int compressor_extract_options(struct compressor *comp,
	int block_size, void *buffer, int size)
{
	if(comp->extract_options == NULL)
		return size ? -1 : 0;
	return comp->extract_options(block_size, buffer, size);
}