]> git.wh0rd.org - dump.git/blame - common/transformation_lzo.c
Regenerate configure.
[dump.git] / common / transformation_lzo.c
CommitLineData
e3956dfb
SP
1#include <stdlib.h>
2#include <config.h>
3
4#ifdef HAVE_LZO
5#include <minilzo.h>
6#endif /* HAVE_LZO */
7
8#include "transformation.h"
9
10/*
11 * Initialize
12 */
13static int
14lzo_initialize(Transformation *xform, int enc)
15{
16}
17
18/*
19 * Shut down.
20 */
21static int
22lzo_shutdown(Transformation *xform)
23{
24 return 0;
25}
26
27/*
28 * Handle forks.
29 */
30static int
31lzo_startNewTape(Transformation *xform, struct tapebuf *tpbin,
32 unsigned long *destlen)
33{
34 return 0;
35}
36
37/*
38 * Start slave process.
39 */
40static int
41lzo_startDiskIOProcess(Transformation *xform)
42{
43 return 0;
44}
45
46/*
47 * End slave process.
48 */
49static int
50lzo_endDiskIOProcess(Transformation *xform)
51{
52 if (xform != NULL) {
53#ifdef HAVE_LZO
54 if (xform->state.lzo.LZO_WorkMem != NULL) {
55 free(xform->state.lzo.LZO_WorkMem);
56 }
57#endif /* HAVE_LZO */
58 free(xform);
59 }
60
61 return 0;
62}
63
64/*
65 * Compress a buffer.
66 */
67static int
68lzo_compress(Transformation *xform, struct tapebuf *tpbin,
69 unsigned long *destlen, const char *src, int srclen, int compressed)
70{
71#ifdef HAVE_LZO
72 lzo_uint *worklen2 = (lzo_uint *) destlen;
73 int compresult;
74
75 compresult = lzo1x_1_compress(src, srclen, tpbin->buf, worklen2,
76 xform->state.lzo.LZO_WorkMem);
77
78 return compresult == LZO_E_OK ? 1 : 0;
79#else
80 return 1;
81#endif /* HAVE_LZO */
82}
83
84/*
85 * Decompress a buffer.
86 */
87static int
88lzo_decompress(Transformation *xform, struct tapebuf *tpbin,
89 unsigned long *destlen, const char *src, int srclen, char **reason)
90{
91#ifdef HAVE_LZO
92 int cresult = 0;
93 lzo_uint destlen2 = *destlen;
94 cresult = lzo1x_decompress(src, srclen, tpbin->buf, &destlen2, NULL);
95 *destlen = destlen2;
96 switch (cresult) {
97 case LZO_E_OK:
98 *reason = "";
99 break;
100 case LZO_E_ERROR:
101 case LZO_E_EOF_NOT_FOUND:
102 *reason = "data error";
103 break;
104 default:
105 *reason = "unknown";
106 }
107
108 return (cresult == LZO_E_OK) ? 1 : 0;
109#else
110 return 1;
111#endif /* HAVE_LZO */
112}
113
114/*
115 * Factory
116 */
117Transformation
118*transformation_lzo_factory(int enc)
119{
120 Transformation *t = (Transformation *) malloc(sizeof (Transformation));
121
122#ifdef HAVE_LZO
123 t->state.lzo.LZO_WorkMem = malloc(LZO1X_1_MEM_COMPRESS);
124 if (!t->state.lzo.LZO_WorkMem)
125 quit("couldn't allocate a compress buffer.\n");
126#else /* HAVE_LZO */
127 t->state = NULL;
128#endif /* HAVE_LZO */
129
130 t->name = "lzo";
131 t->mandatory = 0;
132 t->initialize = &lzo_initialize;
133 t->shutdown = &lzo_shutdown;
134 t->startNewTape = &lzo_startNewTape;
135 t->startDiskIOProcess = &lzo_startDiskIOProcess;
136 t->endDiskIOProcess = &lzo_endDiskIOProcess;
137 t->compress = &lzo_compress;
138 t->decompress = &lzo_decompress;
139
140 return t;
141}