summaryrefslogtreecommitdiff
path: root/rpmio
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-03-18 11:24:52 +0200
committerPanu Matilainen <pmatilai@redhat.com>2009-03-18 11:24:52 +0200
commitfa0898552d3c52249bc41e8104eda02c1bbd3359 (patch)
tree91fb24ddf5c8129872e15e99bcecc175b7de30bc /rpmio
parent8078d0ba24662308b10d9eb0f0da978584b7e757 (diff)
downloadrpm-fa0898552d3c52249bc41e8104eda02c1bbd3359.tar.gz
rpm-fa0898552d3c52249bc41e8104eda02c1bbd3359.tar.bz2
rpm-fa0898552d3c52249bc41e8104eda02c1bbd3359.zip
Add support for "lzma alone" compression format (lzdio)
- "lzma alone" is superseeded by XZ but it's used by Suse and Mandriva distros so it's nice to have as it doesn't need much, only open differs from XZ - rpmlib() dependency versions are an uuuuuuuugly mess here: Suse used "PayloadIsLzma = 4.4.2-1" so that's what we provide to be most compatible (hopefully). Built packages require "PayloadIsLzma <= 4.4.6-1" however to be compatible with Mandriva 2008.0. Did I already say it's ugly? - Based on similar patch in Mandriva by Per Øyvind Karlsen, but avoiding unnecessary renames in rpmio
Diffstat (limited to 'rpmio')
-rw-r--r--rpmio/rpmio.c80
1 files changed, 68 insertions, 12 deletions
diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
index d471433fa..c7040302e 100644
--- a/rpmio/rpmio.c
+++ b/rpmio/rpmio.c
@@ -36,7 +36,7 @@ extern int h_errno;
#define FDONLY(fd) assert(fdGetIo(fd) == fdio)
#define GZDONLY(fd) assert(fdGetIo(fd) == gzdio)
#define BZDONLY(fd) assert(fdGetIo(fd) == bzdio)
-#define LZDONLY(fd) assert(fdGetIo(fd) == xzdio)
+#define LZDONLY(fd) assert(fdGetIo(fd) == xzdio || fdGetIo(fd) == lzdio)
#define UFDONLY(fd) /* assert(fdGetIo(fd) == ufdio) */
@@ -92,6 +92,7 @@ static const FDIO_t ufdio;
static const FDIO_t gzdio;
static const FDIO_t bzdio;
static const FDIO_t xzdio;
+static const FDIO_t lzdio;
/**
*/
@@ -142,6 +143,8 @@ static const char * fdbg(FD_t fd)
#if HAVE_LZMA_H
} else if (fps->io == xzdio) {
sprintf(be, "XZD %p fdno %d", fps->fp, fps->fdno);
+ } else if (fps->io == lzdio) {
+ sprintf(be, "LZD %p fdno %d", fps->fp, fps->fdno);
#endif
} else if (fps->io == fpio) {
sprintf(be, "%s %p(%d) fdno %d",
@@ -1162,7 +1165,7 @@ static const char * getFdErrstr (FD_t fd)
} else
#endif /* HAVE_BZLIB_H */
#ifdef HAVE_LZMA_H
- if (fdGetIo(fd) == xzdio) {
+ if (fdGetIo(fd) == xzdio || fdGetIo(fd) == lzdio) {
errstr = fd->errcookie;
} else
#endif /* HAVE_LZMA_H */
@@ -1198,7 +1201,7 @@ typedef struct lzfile {
} LZFILE;
-static LZFILE *lzopen_internal(const char *path, const char *mode, int fd)
+static LZFILE *lzopen_internal(const char *path, const char *mode, int fd, int xz)
{
int level = 7; /* Use XZ's default compression level if unspecified */
int encoding = 0;
@@ -1232,7 +1235,13 @@ static LZFILE *lzopen_internal(const char *path, const char *mode, int fd)
lzfile->eof = 0;
lzfile->strm = init_strm;
if (encoding) {
- ret = lzma_easy_encoder(&lzfile->strm, level, LZMA_CHECK_SHA256);
+ if (xz) {
+ ret = lzma_easy_encoder(&lzfile->strm, level, LZMA_CHECK_SHA256);
+ } else {
+ lzma_options_lzma options;
+ lzma_lzma_preset(&options, level);
+ ret = lzma_alone_encoder(&lzfile->strm, &options);
+ }
} else { /* lzma_easy_decoder_memusage(level) is not ready yet, use hardcoded limit for now */
ret = lzma_auto_decoder(&lzfile->strm, 100<<20, 0);
}
@@ -1244,16 +1253,28 @@ static LZFILE *lzopen_internal(const char *path, const char *mode, int fd)
return lzfile;
}
+static LZFILE *xzopen(const char *path, const char *mode)
+{
+ return lzopen_internal(path, mode, -1, 1);
+}
+
+static LZFILE *xzdopen(int fd, const char *mode)
+{
+ if (fd < 0)
+ return 0;
+ return lzopen_internal(0, mode, fd, 1);
+}
+
static LZFILE *lzopen(const char *path, const char *mode)
{
- return lzopen_internal(path, mode, -1);
+ return lzopen_internal(path, mode, -1, 0);
}
static LZFILE *lzdopen(int fd, const char *mode)
{
if (fd < 0)
return 0;
- return lzopen_internal(0, mode, fd);
+ return lzopen_internal(0, mode, fd, 0);
}
static int lzflush(LZFILE *lzfile)
@@ -1355,7 +1376,7 @@ static inline void * lzdFileno(FD_t fd)
FDSANE(fd);
for (i = fd->nfps; i >= 0; i--) {
FDSTACK_t * fps = &fd->fps[i];
- if (fps->io != xzdio)
+ if (fps->io != xzdio && fps->io != lzdio)
continue;
rc = fps->fp;
break;
@@ -1364,6 +1385,33 @@ static inline void * lzdFileno(FD_t fd)
return rc;
}
+static FD_t xzdOpen(const char * path, const char * mode)
+{
+ FD_t fd;
+ LZFILE *lzfile;
+ if ((lzfile = xzopen(path, mode)) == NULL)
+ return NULL;
+ fd = fdNew("open (xzdOpen)");
+ fdPop(fd); fdPush(fd, xzdio, lzfile, -1);
+ return fdLink(fd, "xzdOpen");
+}
+
+static FD_t xzdFdopen(void * cookie, const char * fmode)
+{
+ FD_t fd = c2f(cookie);
+ int fdno;
+ LZFILE *lzfile;
+
+ if (fmode == NULL) return NULL;
+ fdno = fdFileno(fd);
+ fdSetFdno(fd, -1); /* XXX skip the fdio close */
+ if (fdno < 0) return NULL;
+ lzfile = xzdopen(fdno, fmode);
+ if (lzfile == NULL) return NULL;
+ fdPush(fd, xzdio, lzfile, fdno);
+ return fdLink(fd, "xzdFdopen");
+}
+
static FD_t lzdOpen(const char * path, const char * mode)
{
FD_t fd;
@@ -1479,11 +1527,16 @@ DBGIO(fd, (stderr, "==>\tlzdClose(%p) rc %lx %s\n", cookie, (unsigned long)rc, f
static struct FDIO_s xzdio_s = {
lzdRead, lzdWrite, lzdSeek, lzdClose, NULL, NULL, NULL, fdFileno,
- NULL, lzdOpen, lzdFileno, lzdFlush
+ NULL, xzdOpen, lzdFileno, lzdFlush
};
-
static const FDIO_t xzdio = &xzdio_s;
+static struct FDIO_s lzdio_s = {
+ lzdRead, lzdWrite, lzdSeek, lzdClose, NULL, NULL, NULL, fdFileno,
+ NULL, lzdOpen, lzdFileno, lzdFlush
+};
+static const FDIO_t lzdio = &lzdio_s;
+
#endif /* HAVE_LZMA_H */
/* =============================================================== */
@@ -1721,6 +1774,9 @@ fprintf(stderr, "*** Fdopen(%p,%s) %s\n", fd, fmode, fdbg(fd));
#if HAVE_LZMA_H
} else if (!strcmp(end, "xzdio")) {
iof = xzdio;
+ fd = xzdFdopen(fd, zstdio);
+ } else if (!strcmp(end, "lzdio")) {
+ iof = lzdio;
fd = lzdFdopen(fd, zstdio);
#endif
} else if (!strcmp(end, "ufdio")) {
@@ -1850,7 +1906,7 @@ int Fflush(FD_t fd)
return bzdFlush(vh);
#endif
#if HAVE_LZMA_H
- if (vh && fdGetIo(fd) == xzdio)
+ if (vh && (fdGetIo(fd) == xzdio || fdGetIo(fd) == lzdio))
return lzdFlush(vh);
#endif
/* FIXME: If we get here, something went wrong above */
@@ -1879,9 +1935,9 @@ int Ferror(FD_t fd)
i--; /* XXX fdio under bzdio always has fdno == -1 */
#endif
#if HAVE_LZMA_H
- } else if (fps->io == xzdio) {
+ } else if (fps->io == xzdio || fps->io == lzdio) {
ec = (fd->syserrno || fd->errcookie != NULL) ? -1 : 0;
- i--; /* XXX fdio under xzdio always has fdno == -1 */
+ i--; /* XXX fdio under xzdio/lzdio always has fdno == -1 */
#endif
} else {
/* XXX need to check ufdio/gzdio/bzdio/fdio errors correctly. */