commit libzio for openSUSE:Factory
Hello community,
here is the log from the commit of package libzio for openSUSE:Factory
checked in at Tue Mar 3 18:34:26 CET 2009.
--------
--- libzio/libzio.changes 2009-02-23 11:05:50.000000000 +0100
+++ /mounts/work_src_done/STABLE/libzio/libzio.changes 2009-02-23 16:15:11.664701042 +0100
@@ -1,0 +2,5 @@
+Mon Feb 23 16:01:17 CET 2009 - werner@suse.de
+
+- Add fseek(3) support for bzip and LZW files
+
+-------------------------------------------------------------------
@@ -6,0 +12 @@
+
calling whatdependson for head-i586
Old:
----
libzio-0.93.diff
libzio-0.93.tar.bz2
New:
----
libzio-0.99.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ libzio.spec ++++++
--- /var/tmp/diff_new_pack.F12904/_old 2009-03-03 18:34:10.000000000 +0100
+++ /var/tmp/diff_new_pack.F12904/_new 2009-03-03 18:34:10.000000000 +0100
@@ -1,5 +1,5 @@
#
-# spec file for package libzio (Version 0.93)
+# spec file for package libzio (Version 0.99)
#
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
@@ -33,12 +33,11 @@
Obsoletes: libzio-64bit
%endif
#
-Version: 0.93
-Release: 2
+Version: 0.99
+Release: 1
Summary: A Library for Accessing Compressed Text Files
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source: libzio-%{version}.tar.bz2
-Patch: libzio-%{version}.diff
%description
Libzio provides a wrapper function for reading or writing gzip or bzip2
@@ -74,7 +73,6 @@
%prep
%setup -q
-%patch
%build
make
@@ -114,6 +112,8 @@
/usr/include/zio.h
%changelog
+* Mon Feb 23 2009 werner@suse.de
+- Add fseek(3) support for bzip and LZW files
* Mon Feb 23 2009 schwab@suse.de
- Fix namespace violations.
* Fri Feb 13 2009 werner@suse.de
++++++ libzio-0.93.tar.bz2 -> libzio-0.99.tar.bz2 ++++++
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.93/fzopen.3.in new/libzio-0.99/fzopen.3.in
--- old/libzio-0.93/fzopen.3.in 2009-02-13 14:03:59.000000000 +0100
+++ new/libzio-0.99/fzopen.3.in 2009-02-23 15:59:59.000000000 +0100
@@ -112,9 +112,9 @@
rb l l l l l.
fread fwrite fseek suffix library
gzip yes yes yes .gz -lz
- bzip2 yes yes no .bz2 -lbz2
-LZW yes no no .Z builtin
-lzma yes yes yes .lzma -llzma (or -llzmadec)
+bzip2 yes yes yes .bz2 -lbz2
+LZW yes no yes .Z builtin
+lzma yes yes(no) yes .lzma -llzma (-llzmadec)
xz yes yes yes .xz -llzma
.TE
.PP
@@ -250,10 +250,8 @@
.B ESPIPE
This happens if
.BR fseek (3)
-is used in the case of bzip2ed files because
-the
-.B libbz2
-does not provide a seek function.
+is used in the case of seesking files is not
+supported.
.\"
.SH WARNINGS
The functions
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.93/Makefile new/libzio-0.99/Makefile
--- old/libzio-0.93/Makefile 2009-02-13 16:10:41.000000000 +0100
+++ new/libzio-0.99/Makefile 2009-02-23 15:55:44.000000000 +0100
@@ -8,7 +8,7 @@
CFLAGS = $(RPM_OPT_FLAGS) -pipe -Wall -D_GNU_SOURCE -D_REENTRANT $(LARGE)
CC = gcc
MAJOR = 0
-MINOR = 93
+MINOR = 99
VERSION = $(MAJOR).$(MINOR)
SONAME = libzio.so.$(MAJOR)
LDMAP = -Wl,--version-script=zio.map
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.93/zio.c new/libzio-0.99/zio.c
--- old/libzio-0.93/zio.c 2009-02-13 16:01:14.000000000 +0100
+++ new/libzio-0.99/zio.c 2009-02-23 15:54:21.000000000 +0100
@@ -20,23 +20,40 @@
#if defined(HAS_ZLIB_H)
static ssize_t zread(void *cookie, char *buf, size_t count)
{
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
return (ssize_t)gzread((gzFile)cookie, (voidp)buf, count);
}
static ssize_t zwrite(void *cookie, const char *buf, size_t count)
{
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
return (ssize_t)gzwrite((gzFile)cookie, (const voidp)buf, count);
}
static zio_int_t zseek(void *cookie, zio_off_t *poffset, int whence)
{
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
return (zio_int_t)gzseek((gzFile)cookie, (z_off_t)(*poffset), whence);
}
static int zclose(void *cookie)
{
+ int status;
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
(void)gzflush((gzFile)cookie, Z_FINISH);
- int status = gzclose((gzFile)cookie);
+ status = gzclose((gzFile)cookie);
return (status >= 0) ? 0 : EOF;
}
@@ -52,26 +69,137 @@
#endif /* !HAS_ZLIB_H */
#if defined(HAS_BZLIB_H)
+# ifndef MIN
+# define MIN(x,y) ((x) < (y) ? (x) : (y))
+# endif
+
+typedef struct bzfile_s {
+ size_t total_out;
+ BZFILE *file;
+ char *mode;
+ char *path;
+ int fd;
+} bzfile_t;
+
static ssize_t bzread(void *cookie, char *buf, size_t count)
{
- return (ssize_t)BZ2_bzread((BZFILE*)cookie, (void*)buf, count);
+ bzfile_t *bzf = (bzfile_t*)cookie;
+ ssize_t len = -1;
+ if (!bzf)
+ goto out;
+ if (bzf->file)
+ len = (ssize_t)BZ2_bzread(bzf->file, (void*)buf, count);
+ if (len > 0)
+ bzf->total_out += len;
+out:
+ if (len < 0)
+ errno = EINVAL;
+ return len;
}
static ssize_t bzwrite(void *cookie, const char *buf, size_t count)
{
- return (ssize_t)BZ2_bzwrite((BZFILE*)cookie, (void*)buf, count);
+ bzfile_t *bzf = (bzfile_t*)cookie;
+ ssize_t len = -1;
+ if (!bzf)
+ goto out;
+ if (bzf->file)
+ len = (ssize_t)BZ2_bzread(bzf->file, (void*)buf, count);
+ if (len > 0)
+ bzf->total_out += len;
+out:
+ if (len < 0)
+ errno = EINVAL;
+ return len;
}
-static zio_int_t bzseek(void *cookie __unused, zio_off_t *poffset __unused, int whence __unused)
+static zio_int_t bzseek(void *cookie, zio_off_t *poffset, int whence)
{
- errno = ESPIPE;
- return -1;
+ bzfile_t *bzf = (bzfile_t*)cookie;
+ off_t offset = (off_t)*poffset;
+ off_t oldpos, newpos;
+ if (!bzf) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ oldpos = (off_t)bzf->total_out;
+ switch (whence) {
+ case SEEK_SET:
+ if (offset < 0)
+ return -1;
+ newpos = offset;
+ break;
+ case SEEK_CUR:
+ if ((offset < 0 && (off_t)(-1 * offset) > oldpos) || (offset > 0 && (offset+oldpos) < oldpos))
+ return -1;
+ newpos = (off_t)bzf->total_out + offset;
+ break;
+ case SEEK_END:
+ newpos = -1;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (whence != SEEK_END && newpos < oldpos) {
+ int status = BZ2_bzflush(bzf->file);
+ BZ2_bzclose(bzf->file);
+ if (status < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (bzf->fd >= 0) {
+ lseek(bzf->fd, 0, SEEK_SET);
+ bzf->file = BZ2_bzdopen(bzf->fd, bzf->mode);
+ } else if (bzf->path) {
+ bzf->file = BZ2_bzopen(bzf->path, bzf->mode);
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+ if (bzf->file == (BZFILE*)0) {
+ errno = EINVAL;
+ return -1;
+ }
+ bzf->total_out = 0;
+ }
+ if (newpos == oldpos)
+ return oldpos;
+ else {
+ char buf[1<<12];
+ while (newpos > oldpos || newpos == -1) {
+ size_t req_size = MIN(sizeof(buf), newpos - oldpos);
+ ssize_t got_size = BZ2_bzread(bzf->file, buf, req_size);
+ if (got_size != (ssize_t)(req_size)) {
+ if (got_size < 0)
+ return -1;
+ else {
+ newpos = oldpos + got_size;
+ break;
+ }
+ }
+ oldpos += got_size;
+ }
+ return newpos;
+ }
}
static int bzclose(void *cookie)
{
- int status = BZ2_bzflush((BZFILE*)cookie);
- BZ2_bzclose((BZFILE*)cookie);
+ bzfile_t *bzf = (bzfile_t*)cookie;
+ int status = -1;
+ if (!bzf) {
+ errno = EINVAL;
+ goto out;
+ }
+ if (bzf->file) {
+ status = BZ2_bzflush(bzf->file);
+ BZ2_bzclose(bzf->file);
+ }
+ free(cookie);
+out:
return (status >= 0) ? 0 : EOF;
}
@@ -91,6 +219,16 @@
# define MIN(x,y) ((x) < (y) ? (x) : (y))
# endif
+typedef struct lzfile_s {
+ uint8_t buf[1<<12];
+ lzma_stream strm;
+ FILE *file;
+ int encoding;
+ int level;
+ int what;
+ int eof;
+} lzfile_t;
+
static lzma_ret lzmaopen(lzma_stream *__restrict strm, const char mode, const char what, int level)
{
lzma_ret ret;
@@ -195,8 +333,7 @@
newpos = offset;
break;
case SEEK_CUR:
- if ((offset < 0 && (off_t)(-1 * offset) > oldpos) ||
- (offset > 0 && (offset+oldpos) < oldpos))
+ if ((offset < 0 && (off_t)(-1 * offset) > oldpos) || (offset > 0 && (offset+oldpos) < oldpos))
return -1;
newpos = (off_t)strm->total_out + offset;
break;
@@ -284,6 +421,10 @@
# if defined(HAS_LZMADEC_H)
static ssize_t lzmaread(void *cookie, char *buf, size_t count)
{
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
return lzmadec_read((lzmadec_FILE*)cookie, (uint8_t*)buf, count);
}
@@ -295,11 +436,19 @@
static zio_int_t lzmaseek(void *cookie, zio_off_t *poffset, int whence)
{
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
return (zio_int_t)lzmadec_seek((lzmadec_FILE*)cookie, (off_t)(*poffset), whence);
}
static int lzmaclose(void *cookie)
{
+ if (!cookie) {
+ errno = EINVAL;
+ return -1;
+ }
int_fast8_t status = lzmadec_close((lzmadec_FILE*)cookie);
return (status >= 0) ? 0 : EOF;
}
@@ -316,9 +465,28 @@
# endif /* !HAS_LZMADEC_H */
#endif /* !HAS_LZMA_H */
+typedef struct lzwfile_s {
+ size_t total_out;
+ LZW_t *file;
+ char *mode;
+ char *path;
+ int fd;
+} lzwfile_t;
+
static ssize_t lzwread(void *cookie, char *buf, size_t count)
{
- return readlzw((LZW_t*)cookie, buf, count);
+ lzwfile_t *lzw = (lzwfile_t*)cookie;
+ ssize_t len = -1;
+ if (!lzw)
+ goto out;
+ if (lzw->file)
+ len = readlzw(lzw->file, buf, count);
+ if (len > 0)
+ lzw->total_out += len;
+out:
+ if (len < 0)
+ errno = EINVAL;
+ return len;
}
static ssize_t lzwwrite(void *cookie, const char *buf, size_t count)
@@ -327,15 +495,84 @@
return -1;
}
-static zio_int_t lzwseek(void *cookie __unused, zio_off_t *poffset __unused, int whence __unused)
+static zio_int_t lzwseek(void *cookie, zio_off_t *poffset, int whence)
{
- errno = ESPIPE;
- return -1;
+ lzwfile_t *lzw = (lzwfile_t*)cookie;
+ off_t offset = (off_t)*poffset;
+ off_t oldpos, newpos;
+ if (!lzw) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ oldpos = (off_t)lzw->total_out;
+ switch (whence) {
+ case SEEK_SET:
+ if (offset < 0)
+ return -1;
+ newpos = offset;
+ break;
+ case SEEK_CUR:
+ if ((offset < 0 && (off_t)(-1 * offset) > oldpos) || (offset > 0 && (offset+oldpos) < oldpos))
+ return -1;
+ newpos = (off_t)lzw->total_out + offset;
+ break;
+ case SEEK_END:
+ newpos = -1;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (whence != SEEK_END && newpos < oldpos) {
+ closelzw(lzw->file);
+ if (lzw->fd >= 0) {
+ lseek(lzw->fd, 0, SEEK_SET);
+ lzw->file = dopenlzw(lzw->fd, lzw->mode);
+ } else if (lzw->path) {
+ lzw->file = openlzw(lzw->path, lzw->mode);
+ } else {
+ errno = EINVAL;
+ return -1;
+ }
+ if (lzw->file == (LZW_t*)0) {
+ errno = EINVAL;
+ return -1;
+ }
+ lzw->total_out = 0;
+ }
+ if (newpos == oldpos)
+ return oldpos;
+ else {
+ char buf[1<<12];
+ while (newpos > oldpos || newpos == -1) {
+ size_t req_size = MIN(sizeof(buf), newpos - oldpos);
+ ssize_t got_size = readlzw(lzw->file, buf, req_size);
+ if (got_size != (ssize_t)(req_size)) {
+ if (got_size < 0)
+ return -1;
+ else {
+ newpos = oldpos + got_size;
+ break;
+ }
+ }
+ oldpos += got_size;
+ }
+ return newpos;
+ }
}
static int lzwclose(void *cookie)
{
- closelzw((LZW_t*)cookie);
+ lzwfile_t *lzw = (lzwfile_t*)cookie;
+ if (!lzw) {
+ errno = EINVAL;
+ return -1;
+ }
+ if (lzw->file)
+ closelzw(lzw->file);
+ free(cookie);
return 0;
}
@@ -347,60 +584,29 @@
.close = (cookie_close_function_t*)&lzwclose,
};
-FILE * fzopen(const char * path, const char * mode)
+static inline char autodetect(char **__restrict path, const char *__restrict check)
{
- FILE * ret = (FILE *)0;
- char * check = (char*)0, * ext = (char*)0;
- size_t n = 0, len;
- unsigned int i;
+ const size_t len = strlen(*path);
+ char *suff = strrchr(*path, '.');
+ char *ext = *path;
char what = 'n';
- if (!mode || !(n = strlen(mode))) {
- errno = EINVAL;
- goto out;
- }
-
- if (!(check = (char*)malloc(n*sizeof(char))))
- goto out;
-
- /* No append mode possible */
- switch (*mode) {
- case 'r': check[0] = 'r'; break;
- case 'w': check[0] = 'w'; break;
- default: errno = EINVAL; goto out;
- }
-
- for (i = 1; i < n; i++) {
- /* We can only open for reading OR writing but NOT for both */
- switch (mode[i]) {
- case '\0': break;
- case '+': errno = EINVAL; goto out;
- case 'b': case 'x': check[i] = mode[i]; continue;
- /* Ingore switches for gzopen() */
- case 'f': case 'h': check[i] = '\0'; continue;
- default: check[i] = '\0'; continue;
- }
- break;
- }
-
- if (!path || !(len = strlen(path))) {
- errno = EINVAL;
- goto out;
+ if (suff) {
+ suff++;
+ if (strcmp(suff, "z" ) == 0)
+ what = 'z';
+ else if (strcmp(suff, "gz" ) == 0)
+ what = 'g';
+ else if (strcmp(suff, "Z" ) == 0)
+ what = 'Z';
+ else if (strcmp(suff, "bz2" ) == 0)
+ what = 'b';
+ else if (strcmp(suff, "lzma") == 0)
+ what = 'l';
+ else if (strcmp(suff, "xz" ) == 0)
+ what = 'x';
}
- if (strcmp(path + len - 2, ".z" ) == 0)
- what = 'z';
- else if (strcmp(path + len - 3, ".gz" ) == 0)
- what = 'g';
- else if (strcmp(path + len - 3, ".Z" ) == 0)
- what = 'Z';
- else if (strcmp(path + len - 4, ".bz2" ) == 0)
- what = 'b';
- else if (strcmp(path + len - 5, ".lzma") == 0)
- what = 'l';
- else if (strcmp(path + len - 3, ".xz") == 0)
- what = 'x';
-
if (what == 'n' && *check == 'r') {
int olderr, fd;
struct stat st;
@@ -408,39 +614,40 @@
ext = malloc(sizeof(char)*(len + 5 + 1));
if (!ext)
goto out;
- strcpy(ext, path);
+ strcpy(ext, *path);
+ suff = (ext+len);
olderr = errno;
if (stat(strcat(ext, ".gz"), &st) == 0) {
what = 'g';
goto skip;
}
- *(ext + len) = '\0';
+ *suff = '\0';
if (stat(strcat(ext, ".bz2"), &st) == 0) {
what = 'b';
goto skip;
}
- *(ext + len) = '\0';
+ *suff = '\0';
if (stat(strcat(ext, ".z"), &st) == 0) {
what = 'z';
goto skip;
}
- *(ext + len) = '\0';
+ *suff = '\0';
if (stat(strcat(ext, ".Z"), &st) == 0) {
what = 'Z';
goto skip;
}
- *(ext + len) = '\0';
+ *suff = '\0';
if (stat(strcat(ext, ".lzma"), &st) == 0) {
what = 'l';
goto skip;
}
- *(ext + len) = '\0';
+ *suff = '\0';
if (stat(strcat(ext, ".xz"), &st) == 0) {
what = 'x';
goto skip;
}
- *(ext + len) = '\0';
+ *suff = '\0';
if ((fd = open(ext, O_RDONLY|O_NOCTTY)) < 0)
goto skip;
@@ -461,18 +668,64 @@
what = 'x';
}
close(fd);
-
skip:
errno = olderr;
- } else
- ext = (char *)path;
+ }
+out:
+ *path = ext;
+ return what;
+}
+
+FILE * fzopen(const char * path, const char * mode)
+{
+ FILE * ret = (FILE *)0;
+ char * check = (char*)0, * ext = (char*)0;
+ size_t n = 0, len;
+ unsigned int i;
+ char what = 'n';
+
+ if (!mode || !(n = strlen(mode))) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ if (!(check = (char*)malloc(n*sizeof(char))))
+ goto out;
+
+ /* No append mode possible */
+ switch (*mode) {
+ case 'r': check[0] = 'r'; break;
+ case 'w': check[0] = 'w'; break;
+ default: errno = EINVAL; goto out;
+ }
+
+ for (i = 1; i < n; i++) {
+ /* We can only open for reading OR writing but NOT for both */
+ switch (mode[i]) {
+ case '\0': break;
+ case '+': errno = EINVAL; goto out;
+ case 'b': case 'x': check[i] = mode[i]; continue;
+ /* Ingore switches for gzopen() */
+ case 'f': case 'h': check[i] = '\0'; continue;
+ default: check[i] = '\0'; continue;
+ }
+ break;
+ }
+
+ if (!path || !(len = strlen(path))) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ ext = (char *)path;
+ what = autodetect(&ext, check);
switch (what) {
case 'g':
case 'z': /* Is this correct? Old gzip magic */
#if defined(HAS_ZLIB_H)
{
- gzFile cookie = (gzFile)0;
+ gzFile cookie;
if (&gzopen == NULL) {
errno = ENOSYS;
@@ -485,7 +738,7 @@
goto out;
}
- if (!(ret = fopencookie(cookie, check, ioz))) {
+ if (!(ret = fopencookie((void*)cookie, check, ioz))) {
gzclose(cookie);
errno = EINVAL;
goto out;
@@ -501,20 +754,32 @@
break;
case 'Z':
{
- LZW_t *cookie;
+ lzwfile_t *__restrict cookie;
if (*mode != 'r') {
errno = ENOTSUP;
goto out;
}
- if (!(cookie = openlzw(ext, mode))) {
+ if (posix_memalign((void*)&cookie, sizeof(void*), alignof(lzwfile_t)+strsize(ext)+strsize(mode)) != 0)
+ goto out;
+ memset(cookie, 0, alignof(lzwfile_t)+strsize(ext)+strsize(mode));
+
+ cookie->fd = -1;
+ cookie->mode = ((char*)cookie)+alignof(lzwfile_t);
+ cookie->path = cookie->mode + strsize(mode);
+ strcpy(cookie->mode, mode);
+ strcpy(cookie->path, ext);
+
+ if (!(cookie->file = openlzw(ext, mode))) {
+ free(cookie);
if (!errno)
errno = ENOMEM;
goto out;
}
- if (!(ret = fopencookie(cookie, check, iolzw))) {
- closelzw(cookie);
+ if (!(ret = fopencookie((void*)cookie, check, iolzw))) {
+ closelzw(cookie->file);
+ free(cookie);
errno = EINVAL;
goto out;
}
@@ -527,21 +792,41 @@
case 'b':
#if defined(HAS_BZLIB_H)
{
- BZFILE* cookie = (BZFILE*)0;
+ bzfile_t *__restrict cookie;
+ int level = 5;
if (&BZ2_bzopen == NULL) {
errno = ENOSYS;
goto out;
}
- if (!(cookie = BZ2_bzopen(ext, mode))) {
+ if (posix_memalign((void*)&cookie, sizeof(void*), alignof(bzfile_t)+strsize(ext)+strsize(mode)) != 0)
+ goto out;
+ memset(cookie, 0, alignof(bzfile_t)+strsize(ext)+strsize(mode));
+
+ for (i = 1; i < n; i++) {
+ if (mode[i] >= '0' && mode[i] <= '9') {
+ level = (int)mode[i];
+ break;
+ }
+ }
+
+ cookie->fd = -1;
+ cookie->mode = ((char*)cookie)+alignof(bzfile_t);
+ cookie->path = cookie->mode+strsize(mode);
+ strcpy(cookie->mode, mode);
+ strcpy(cookie->path, ext);
+
+ if (!(cookie->file = BZ2_bzopen(ext, mode))) {
+ free(cookie);
if (!errno)
errno = ENOMEM;
goto out;
}
- if (!(ret = fopencookie(cookie, check, iobz))) {
- BZ2_bzclose(cookie);
+ if (!(ret = fopencookie((void*)cookie, check, iobz))) {
+ BZ2_bzclose(cookie->file);
+ free(cookie);
errno = EINVAL;
goto out;
}
@@ -559,7 +844,7 @@
case 'x':
{
int level = LZMA_PRESET_DEFAULT;
- lzfile_t * cookie = (lzfile_t*)0;
+ lzfile_t *__restrict cookie;
lzma_ret lret;
if (&lzma_auto_decoder == NULL) {
@@ -567,9 +852,9 @@
goto out;
}
- if ((cookie = (lzfile_t*)malloc(sizeof(lzfile_t))) == NULL)
+ if (posix_memalign((void*)&cookie, sizeof(void*), alignof(lzfile_t)) != 0)
goto out;
- memset(cookie, 0, sizeof(lzfile_t));
+ memset(cookie, 0, alignof(lzfile_t));
if ((cookie->file = fopen(ext, check)) == NULL) {
free(cookie);
@@ -589,13 +874,14 @@
cookie->level = level;
cookie->encoding = (check[0] == 'w') ? 1 : 0;
lret = lzmaopen(&cookie->strm, check[0], what, level);
+
if (lret != LZMA_OK) {
fclose(cookie->file);
free(cookie);
errno = EINVAL;
goto out;
}
- if (!(ret = fopencookie(cookie, check, iolzma))) {
+ if (!(ret = fopencookie((void*)cookie, check, iolzma))) {
lzma_end(&cookie->strm);
fclose(cookie->file);
free(cookie);
@@ -612,10 +898,10 @@
case 'x':
errno = ENOTSUP;
break;
-# if defined(HAS_LZMADEC_H)
case 'l':
+# if defined(HAS_LZMADEC_H)
{
- lzmadec_FILE* cookie = (lzmadec_FILE*)0;
+ lzmadec_FILE* cookie;
if (*mode != 'r') {
errno = ENOTSUP;
@@ -633,7 +919,7 @@
goto out;
}
- if (!(ret = fopencookie(cookie, check, iolzma))) {
+ if (!(ret = fopencookie((void*)cookie, check, iolzma))) {
lzmadec_close(cookie);
errno = EINVAL;
goto out;
@@ -644,10 +930,9 @@
# endif
}
# else /* !HAS_LZMADEC_H */
- case 'l':
errno = ENOTSUP;
# endif /* !HAS_LZMADEC_H */
-#endif /* HAS_LZMA_H */
+#endif /* !HAS_LZMA_H */
break;
default:
ret = fopen(ext, mode);
@@ -703,7 +988,7 @@
case 'z': /* Is this correct? Old gzip magic */
#if defined(HAS_ZLIB_H)
{
- gzFile cookie = (gzFile)0;
+ gzFile cookie;
if (&gzdopen == NULL) {
errno = ENOSYS;
@@ -716,7 +1001,7 @@
goto out;
}
- if (!(ret = fopencookie(cookie, check, ioz))) {
+ if (!(ret = fopencookie((void*)cookie, check, ioz))) {
gzclose(cookie);
errno = EINVAL;
goto out;
@@ -732,20 +1017,30 @@
break;
case 'Z':
{
- LZW_t *cookie;
+ lzwfile_t *__restrict cookie;
if (*mode != 'r') {
errno = ENOTSUP;
goto out;
}
- if (!(cookie = dopenlzw(fildes, mode))) {
+ if (posix_memalign((void*)&cookie, sizeof(void*), alignof(lzwfile_t)+strsize(mode)) != 0)
+ goto out;
+ memset(cookie, 0, alignof(lzwfile_t)+strsize(mode));
+
+ cookie->fd = fildes;
+ cookie->mode = ((char*)cookie)+alignof(lzwfile_t);
+ strcpy(cookie->mode, mode);
+
+ if (!(cookie->file = dopenlzw(fildes, mode))) {
+ free(cookie);
if (!errno)
errno = ENOMEM;
goto out;
}
- if (!(ret = fopencookie(cookie, check, iolzw))) {
- closelzw(cookie);
+ if (!(ret = fopencookie((void*)cookie, check, iolzw))) {
+ closelzw(cookie->file);
+ free(cookie);
errno = EINVAL;
goto out;
}
@@ -758,21 +1053,43 @@
case 'b':
#if defined(HAS_BZLIB_H)
{
- BZFILE* cookie = (BZFILE*)0;
+ bzfile_t *__restrict cookie;
+ int level = 5;
if (&BZ2_bzdopen == NULL) {
errno = ENOSYS;
goto out;
}
- if (!(cookie = BZ2_bzdopen(fildes, mode))) {
+ if (posix_memalign((void*)&cookie, sizeof(void*), alignof(bzfile_t)+strsize(mode)) != 0)
+ goto out;
+ memset(cookie, 0, alignof(bzfile_t)+strsize(mode));
+
+ for (i = 1; i < n; i++) {
+ if (mode[i] >= '0' && mode[i] <= '9') {
+ level = (int)mode[i];
+ break;
+ }
+ }
+
+ cookie->fd = fildes;
+ cookie->mode = ((char*)cookie)+alignof(bzfile_t);
+ strcpy(cookie->mode, mode);
+
+ if (cookie->mode == (char*)0) {
+ free(cookie);
+ goto out;
+ }
+ if (!(cookie->file = BZ2_bzdopen(fildes, mode))) {
+ free(cookie);
if (!errno)
errno = ENOMEM;
goto out;
}
- if (!(ret = fopencookie(cookie, check, iobz))) {
- BZ2_bzclose(cookie);
+ if (!(ret = fopencookie((void*)cookie, check, iobz))) {
+ BZ2_bzclose(cookie->file);
+ free(cookie);
errno = EINVAL;
goto out;
}
@@ -790,7 +1107,7 @@
case 'x':
{
int level = LZMA_PRESET_DEFAULT;
- lzfile_t * cookie = (lzfile_t*)0;
+ lzfile_t *__restrict cookie;
lzma_ret lret;
if (&lzma_auto_decoder == NULL) {
@@ -798,9 +1115,9 @@
goto out;
}
- if ((cookie = (lzfile_t*)malloc(sizeof(lzfile_t))) == NULL)
+ if (posix_memalign((void*)&cookie, sizeof(void*), alignof(lzfile_t)) != 0)
goto out;
- memset(cookie, 0, sizeof(lzfile_t));
+ memset(cookie, 0, alignof(lzfile_t));
if ((cookie->file = fdopen(fildes, check)) == NULL) {
free(cookie);
@@ -826,7 +1143,7 @@
errno = EINVAL;
goto out;
}
- if (!(ret = fopencookie(cookie, check, iolzma))) {
+ if (!(ret = fopencookie((void*)cookie, check, iolzma))) {
lzma_end(&cookie->strm);
fclose(cookie->file);
free(cookie);
@@ -846,7 +1163,7 @@
case 'l':
# if defined(HAS_LZMADEC_H)
{
- lzmadec_FILE* cookie = (lzmadec_FILE*)0;
+ lzmadec_FILE* cookie;
if (*mode != 'r') {
errno = ENOTSUP;
@@ -864,7 +1181,7 @@
goto out;
}
- if (!(ret = fopencookie(cookie, check, iolzma))) {
+ if (!(ret = fopencookie((void*)cookie, check, iolzma))) {
lzmadec_close(cookie);
errno = EINVAL;
goto out;
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.93/zioP.h new/libzio-0.99/zioP.h
--- old/libzio-0.93/zioP.h 2009-02-13 16:27:29.000000000 +0100
+++ new/libzio-0.99/zioP.h 2009-02-23 14:54:34.000000000 +0100
@@ -33,15 +33,17 @@
#include
participants (1)
-
root@Hilbert.suse.de