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
|
#include "system.h"
#include <rpmlib.h>
#include <rpmio.h>
/*@access FD_t@*/
/* =============================================================== */
/* Support for BZIP2 library.
*/
#ifdef HAVE_BZLIB_H
#include <bzlib.h>
BZFILE * bzdFileno(FD_t fd) {
return (fd != NULL ? ((BZFILE *)fd->fd_bzd) : NULL);
}
FD_t bzdOpen(const char *pathname, const char *mode) {
FD_t fd;
BZFILE *bzfile;;
if ((bzfile = bzopen(pathname, mode)) == NULL)
return NULL;
fd = fdNew();
fd->fd_bzd = bzfile;
return fd;
}
FD_t bzdFdopen(FD_t fd, const char *mode) {
BZFILE *bzfile = bzdopen(fdFileno(fd), mode);
if (bzfile != NULL) {
fd->fd_fd = -1;
fd->fd_bzd = bzfile;
return fd;
}
return NULL;
}
ssize_t bzdRead(FD_t fd, void * buf, size_t count) {
return bzread(bzdFileno(fd), buf, count);
}
ssize_t bzdWrite(FD_t fd, const void * buf, size_t count) {
return bzwrite(bzdFileno(fd), (void *)buf, count);
}
int bzdFlush(FD_t fd) {
return bzflush(bzdFileno(fd));
}
const char * bzdStrerror(FD_t fd) {
int bzerr;
return bzerror(bzdFileno(fd), &bzerr);
}
int bzdClose(FD_t fd) {
BZFILE *bzfile;
if (fd != NULL && (bzfile = bzdFileno(fd)) != NULL) {
fd->fd_fd = -1;
fd->fd_bzd = NULL;
fd->fd_gzd = NULL;
free(fd);
bzclose(bzfile);
return 0;
}
return -2;
}
#endif /* HAVE_BZLIB_H */
|