OpenWrt – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
4 | office | 1 | --- a/lib/Kconfig |
2 | +++ b/lib/Kconfig |
||
3 | @@ -247,6 +247,9 @@ config LZMA_COMPRESS |
||
4 | config LZMA_DECOMPRESS |
||
5 | tristate |
||
6 | |||
7 | +config RLE_DECOMPRESS |
||
8 | + tristate |
||
9 | + |
||
10 | # |
||
11 | # These all provide a common interface (hence the apparent duplication with |
||
12 | # ZLIB_INFLATE; DECOMPRESS_GZIP is just a wrapper.) |
||
13 | --- a/lib/Makefile |
||
14 | +++ b/lib/Makefile |
||
15 | @@ -120,6 +120,7 @@ obj-$(CONFIG_XZ_DEC) += xz/ |
||
16 | obj-$(CONFIG_RAID6_PQ) += raid6/ |
||
17 | obj-$(CONFIG_LZMA_COMPRESS) += lzma/ |
||
18 | obj-$(CONFIG_LZMA_DECOMPRESS) += lzma/ |
||
19 | +obj-$(CONFIG_RLE_DECOMPRESS) += rle.o |
||
20 | |||
21 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o |
||
22 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o |
||
23 | --- /dev/null |
||
24 | +++ b/include/linux/rle.h |
||
25 | @@ -0,0 +1,18 @@ |
||
26 | +#ifndef _RLE_H_ |
||
27 | +#define _RLE_H_ |
||
28 | + |
||
29 | +#ifdef CONFIG_RLE_DECOMPRESS |
||
30 | +int rle_decode(const unsigned char *src, size_t srclen, |
||
31 | + unsigned char *dst, size_t dstlen, |
||
32 | + size_t *src_done, size_t *dst_done); |
||
33 | +#else |
||
34 | +static inline int |
||
35 | +rle_decode(const unsigned char *src, size_t srclen, |
||
36 | + unsigned char *dst, size_t dstlen, |
||
37 | + size_t *src_done, size_t *dst_done) |
||
38 | +{ |
||
39 | + return -ENOTSUPP; |
||
40 | +} |
||
41 | +#endif /* CONFIG_RLE_DECOMPRESS */ |
||
42 | + |
||
43 | +#endif /* _RLE_H_ */ |
||
44 | --- /dev/null |
||
45 | +++ b/lib/rle.c |
||
46 | @@ -0,0 +1,78 @@ |
||
47 | +/* |
||
48 | + * RLE decoding routine |
||
49 | + * |
||
50 | + * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org> |
||
51 | + * |
||
52 | + * This program is free software; you can redistribute it and/or modify it |
||
53 | + * under the terms of the GNU General Public License version 2 as published |
||
54 | + * by the Free Software Foundation. |
||
55 | + */ |
||
56 | + |
||
57 | +#include <linux/kernel.h> |
||
58 | +#include <linux/module.h> |
||
59 | +#include <linux/rle.h> |
||
60 | + |
||
61 | +int rle_decode(const unsigned char *src, size_t srclen, |
||
62 | + unsigned char *dst, size_t dstlen, |
||
63 | + size_t *src_done, size_t *dst_done) |
||
64 | +{ |
||
65 | + size_t srcpos, dstpos; |
||
66 | + int ret; |
||
67 | + |
||
68 | + srcpos = 0; |
||
69 | + dstpos = 0; |
||
70 | + ret = -EINVAL; |
||
71 | + |
||
72 | + /* sanity checks */ |
||
73 | + if (!src || !srclen || !dst || !dstlen) |
||
74 | + goto out; |
||
75 | + |
||
76 | + while (1) { |
||
77 | + char count; |
||
78 | + |
||
79 | + if (srcpos >= srclen) |
||
80 | + break; |
||
81 | + |
||
82 | + count = (char) src[srcpos++]; |
||
83 | + if (count == 0) { |
||
84 | + ret = 0; |
||
85 | + break; |
||
86 | + } |
||
87 | + |
||
88 | + if (count > 0) { |
||
89 | + unsigned char c; |
||
90 | + |
||
91 | + if (srcpos >= srclen) |
||
92 | + break; |
||
93 | + |
||
94 | + c = src[srcpos++]; |
||
95 | + |
||
96 | + while (count--) { |
||
97 | + if (dstpos >= dstlen) |
||
98 | + break; |
||
99 | + |
||
100 | + dst[dstpos++] = c; |
||
101 | + } |
||
102 | + } else { |
||
103 | + count *= -1; |
||
104 | + |
||
105 | + while (count--) { |
||
106 | + if (srcpos >= srclen) |
||
107 | + break; |
||
108 | + if (dstpos >= dstlen) |
||
109 | + break; |
||
110 | + dst[dstpos++] = src[srcpos++]; |
||
111 | + } |
||
112 | + } |
||
113 | + } |
||
114 | + |
||
115 | +out: |
||
116 | + if (src_done) |
||
117 | + *src_done = srcpos; |
||
118 | + if (dst_done) |
||
119 | + *dst_done = dstpos; |
||
120 | + |
||
121 | + return ret; |
||
122 | +} |
||
123 | + |
||
124 | +EXPORT_SYMBOL_GPL(rle_decode); |