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
|
#include "dk4conf.h"
#include <stdio.h>
#include "dk4strmf.h"
#include "dk4strmco.h"
$!trace-include
int main(void)
{
char buf[4096];
dk4_stream_t *fstrm = NULL;
dk4_stream_t *cstrm = NULL;
size_t szbuf = sizeof(buf);
size_t br;
int res;
$!trace-init test-dk4strmco.deb
$? "+ main"
fstrm = dk4stream_open_for_file(
stdout, DK4_STREAM_WRITE, 0, 4096, NULL
);
if (NULL == fstrm) {
fputs("ERROR: Failed to open stream for stdout!\n", stderr);
fflush(stderr);
goto finished;
}
cstrm = dk4strmco_open(
fstrm,
DK4_STRMCO_PP_NONE, DK4_STRMCO_CO_FLATE, DK4_STRMCO_OE_ASCII85,
(DK4_STRMCO_FL_EOD_OE | DK4_STRMCO_FL_NL_OE),
NULL
);
if (NULL == cstrm) {
fputs("ERROR: Failed to open compressing stream!\n", stderr);
fflush(stderr);
goto finished;
}
do {
br = fread(buf, 1, szbuf, stdin);
if (0 < br) {
res = dk4stream_write(cstrm, buf, br, NULL);
if (0 == res) {
fputs("ERROR: Write operation failed!\n", stderr);
fflush(stderr);
}
}
} while ((!feof(stdin)) && (0 < br));
finished:
if (NULL != cstrm) {
res = dk4stream_close(cstrm, NULL);
if (0 == res) {
fputs("ERROR: Failed to close compressed stream!\n", stderr);
fflush(stderr);
}
}
if (NULL != fstrm) {
res = dk4stream_close(fstrm, NULL);
if (0 == res) {
fputs("ERROR: Failed to close file stream!\n", stderr);
fflush(stderr);
}
}
$? "- main"
$!trace-end
return 0;
}
/* vim: set ai sw=4 ts=4 : */
|