SHA256
3
0
forked from pool/libzio

Accepting request 286992 from devel:libraries:c_c++

1

OBS-URL: https://build.opensuse.org/request/show/286992
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/libzio?expand=0&rev=39
This commit is contained in:
Dominique Leuenberger 2015-02-27 09:55:56 +00:00 committed by Git OBS Bridge
commit ae3303492a
5 changed files with 14 additions and 499 deletions

View File

@ -1,458 +0,0 @@
--- zio.c
+++ zio.c 2013-02-26 16:40:47.165444637 +0000
@@ -42,6 +42,7 @@ static zio_int_t zseek(void *cookie, zio
errno = EINVAL;
return -1;
}
+ off_t offset = (off_t)*poffset;
return (zio_int_t)gzseek((gzFile)cookie, (z_off_t)(*poffset), whence);
}
@@ -74,8 +75,9 @@ static cookie_io_functions_t ioz = {
# endif
typedef struct bzfile_s {
- size_t total_out;
+ size_t position;
BZFILE *file;
+ FILE *stdio;
char *mode;
char *path;
int fd;
@@ -90,7 +92,7 @@ static ssize_t bzread(void *cookie, ch
if (bzf->file)
len = (ssize_t)BZ2_bzread(bzf->file, (void*)buf, count);
if (len > 0)
- bzf->total_out += len;
+ bzf->position += len;
out:
if (len < 0)
errno = EINVAL;
@@ -104,9 +106,9 @@ static ssize_t bzwrite(void *cookie, c
if (!bzf)
goto out;
if (bzf->file)
- len = (ssize_t)BZ2_bzread(bzf->file, (void*)buf, count);
+ len = (ssize_t)BZ2_bzwrite(bzf->file, (void*)buf, count);
if (len > 0)
- bzf->total_out += len;
+ bzf->position += len;
out:
if (len < 0)
errno = EINVAL;
@@ -116,24 +118,29 @@ out:
static zio_int_t bzseek(void *cookie, zio_off_t *poffset, int whence)
{
bzfile_t *bzf = (bzfile_t*)cookie;
- off_t offset = (off_t)*poffset;
- off_t oldpos, newpos;
+ off_t offset, curpos, newpos;
if (!bzf) {
errno = EINVAL;
return -1;
}
- oldpos = (off_t)bzf->total_out;
+ offset = (off_t)*poffset;
+ curpos = (off_t)bzf->position;
+
switch (whence) {
case SEEK_SET:
- if (offset < 0)
+ if (offset < 0) {
+ errno = EINVAL;
return -1;
+ }
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) > curpos) || (offset > 0 && (offset+curpos) < curpos)) {
+ errno = EINVAL;
return -1;
- newpos = (off_t)bzf->total_out + offset;
+ }
+ newpos = curpos + offset;
break;
case SEEK_END:
newpos = -1;
@@ -143,7 +150,7 @@ static zio_int_t bzseek(void *cookie, zi
return -1;
}
- if (whence != SEEK_END && newpos < oldpos) {
+ if (whence != SEEK_END && newpos < curpos) {
int status = BZ2_bzflush(bzf->file);
BZ2_bzclose(bzf->file);
if (status < 0) {
@@ -163,27 +170,36 @@ static zio_int_t bzseek(void *cookie, zi
errno = EINVAL;
return -1;
}
- bzf->total_out = 0;
+ curpos = (off_t)0;
+ bzf->position = curpos;
}
- if (newpos == oldpos)
- return oldpos;
- else {
+ if (newpos == curpos)
+ goto out;
+ if (newpos == -1) {
+ char buf[1<<12];
+ while (1) {
+ ssize_t got_size = BZ2_bzread(bzf->file, buf, sizeof(buf));
+ if (got_size < 0)
+ return -1;
+ if (got_size == 0)
+ break;
+ curpos += got_size;
+ }
+ } else {
char buf[1<<12];
- while (newpos > oldpos || newpos == -1) {
- size_t req_size = MIN(sizeof(buf), newpos - oldpos);
+ while (newpos > curpos) {
+ size_t req_size = MIN(sizeof(buf), newpos - curpos);
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;
+ if (got_size < 0)
+ return -1;
+ if (got_size == 0)
+ break;
+ curpos += got_size;
}
- return newpos;
}
+out:
+ bzf->position = curpos;
+ return curpos;
}
static int bzclose(void *cookie)
@@ -223,6 +239,7 @@ typedef struct lzfile_s {
uint8_t buf[1<<12];
lzma_stream strm;
FILE *file;
+ FILE *stdio;
int encoding;
int level;
int what;
@@ -291,9 +308,9 @@ static ssize_t lzmawrite(void *cookie,
lzfile_t *lzma = (lzfile_t*)cookie;
lzma_stream *strm;
if (!lzma || !lzma->encoding)
- return -1;
+ return -1;
if (!count)
- return 0;
+ return 0;
strm = &lzma->strm;
strm->next_in = (uint8_t*)buf;
@@ -318,24 +335,31 @@ static ssize_t lzmawrite(void *cookie,
static zio_int_t lzmaseek(void *cookie, zio_off_t *poffset, int whence)
{
lzfile_t *lzma = (lzfile_t*)cookie;
- off_t offset = (off_t)*poffset;
lzma_stream *strm;
- off_t oldpos, newpos;
- if (!lzma)
+ off_t offset, curpos, newpos;
+ if (!lzma) {
+ errno = EINVAL;
return -1;
+ }
+
strm = &lzma->strm;
+ offset = (off_t)*poffset;
+ curpos = (off_t)strm->total_out;
- oldpos = (off_t)strm->total_out;
switch (whence) {
case SEEK_SET:
- if (offset < 0)
+ if (offset < 0) {
+ errno = EINVAL;
return -1;
+ }
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) > curpos) || (offset > 0 && (offset+curpos) < curpos)) {
+ errno = EINVAL;
return -1;
- newpos = (off_t)strm->total_out + offset;
+ }
+ newpos = curpos + offset;
break;
case SEEK_END:
newpos = -1;
@@ -344,37 +368,51 @@ static zio_int_t lzmaseek(void *cookie,
errno = EINVAL;
return -1;
}
-
- if (whence != SEEK_END && newpos < oldpos) {
+ if (whence != SEEK_END && newpos < curpos) {
lzma_ret ret;
+
lzma_end(strm);
+ lzma->strm = (lzma_stream)LZMA_STREAM_INIT;
+ strm = &lzma->strm;
+
rewind(lzma->file);
+ clearerr(lzma->file);
+ lzma->eof = 0;
+
ret = lzmaopen(strm, lzma->encoding ? 'w' : 'r', lzma->what, lzma->level);
if (ret != LZMA_OK || strm->total_out != 0) {
fclose(lzma->file);
errno = EINVAL;
return -1;
}
+ curpos = (off_t)0;
}
- if (newpos == oldpos)
- return oldpos;
- else {
+ if (newpos == curpos)
+ goto out;
+ if (newpos == -1) {
+ char buf[sizeof(lzma->buf)];
+ while (1) {
+ ssize_t got_size = lzmaread(cookie, buf, sizeof(buf));
+ if (got_size < 0)
+ return -1;
+ if (got_size == 0)
+ break;
+ curpos += got_size;
+ }
+ } else {
char buf[sizeof(lzma->buf)];
- while (newpos > oldpos || newpos == -1) {
- size_t req_size = MIN(sizeof(buf), newpos - oldpos);
+ while (newpos > curpos) {
+ size_t req_size = MIN(sizeof(buf), newpos - curpos);
ssize_t got_size = lzmaread(cookie, 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;
+ if (got_size < 0)
+ return -1;
+ if (got_size == 0)
+ break;
+ curpos += got_size;
}
- return newpos;
}
+out:
+ return curpos;
}
static int lzmaclose(void *cookie)
@@ -466,8 +504,9 @@ static cookie_io_functions_t iolzma = {
#endif /* !HAS_LZMA_H */
typedef struct lzwfile_s {
- size_t total_out;
+ size_t position;
LZW_t *file;
+ FILE *stdio;
char *mode;
char *path;
int fd;
@@ -482,7 +521,7 @@ static ssize_t lzwread(void *cookie, c
if (lzw->file)
len = readlzw(lzw->file, buf, count);
if (len > 0)
- lzw->total_out += len;
+ lzw->position += len;
out:
if (len < 0)
errno = EINVAL;
@@ -498,24 +537,29 @@ static ssize_t lzwwrite(void *cookie,
static zio_int_t lzwseek(void *cookie, zio_off_t *poffset, int whence)
{
lzwfile_t *lzw = (lzwfile_t*)cookie;
- off_t offset = (off_t)*poffset;
- off_t oldpos, newpos;
+ off_t offset, curpos, newpos;
if (!lzw) {
errno = EINVAL;
return -1;
}
- oldpos = (off_t)lzw->total_out;
+ offset = (off_t)*poffset;
+ curpos = (off_t)lzw->position;
+
switch (whence) {
case SEEK_SET:
- if (offset < 0)
+ if (offset < 0) {
+ errno = EINVAL;
return -1;
+ }
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) > curpos) || (offset > 0 && (offset+curpos) < curpos)) {
+ errno = EINVAL;
return -1;
- newpos = (off_t)lzw->total_out + offset;
+ }
+ newpos = curpos + offset;
break;
case SEEK_END:
newpos = -1;
@@ -525,7 +569,7 @@ static zio_int_t lzwseek(void *cookie, z
return -1;
}
- if (whence != SEEK_END && newpos < oldpos) {
+ if (whence != SEEK_END && newpos < curpos) {
closelzw(lzw->file);
if (lzw->fd >= 0) {
lseek(lzw->fd, 0, SEEK_SET);
@@ -540,27 +584,36 @@ static zio_int_t lzwseek(void *cookie, z
errno = EINVAL;
return -1;
}
- lzw->total_out = 0;
+ curpos = (off_t)0;
+ lzw->position = curpos;
}
- if (newpos == oldpos)
- return oldpos;
- else {
+ if (newpos == curpos)
+ goto out;
+ if (newpos == -1) {
+ char buf[1<<12];
+ while (1) {
+ ssize_t got_size = readlzw(lzw->file, buf, sizeof(buf));
+ if (got_size < 0)
+ return -1;
+ if (got_size == 0)
+ break;
+ curpos += got_size;
+ }
+ } else {
char buf[1<<12];
- while (newpos > oldpos || newpos == -1) {
- size_t req_size = MIN(sizeof(buf), newpos - oldpos);
+ while (newpos > curpos) {
+ size_t req_size = MIN(sizeof(buf), newpos - curpos);
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;
+ if (got_size < 0)
+ return -1;
+ if (got_size == 0)
+ break;
+ curpos += got_size;
}
- return newpos;
}
+out:
+ lzw->position = curpos;
+ return curpos;
}
static int lzwclose(void *cookie)
@@ -787,6 +840,7 @@ FILE * fzopen(const char * path, const c
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
break;
case 'b':
@@ -834,6 +888,7 @@ FILE * fzopen(const char * path, const c
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
#else /* !HAS_BZLIB_H */
errno = ENOTSUP;
@@ -892,6 +947,7 @@ FILE * fzopen(const char * path, const c
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
break;
#else /* !HAS_LZMA_H */
@@ -928,6 +984,7 @@ FILE * fzopen(const char * path, const c
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
# else /* !HAS_LZMADEC_H */
errno = ENOTSUP;
@@ -1048,6 +1105,7 @@ FILE * fdzopen(int fildes, const char *
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
break;
case 'b':
@@ -1097,6 +1155,7 @@ FILE * fdzopen(int fildes, const char *
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
#else /* !HAS_BZLIB_H */
errno = ENOTSUP;
@@ -1137,6 +1196,7 @@ FILE * fdzopen(int fildes, const char *
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);
@@ -1154,6 +1214,7 @@ FILE * fdzopen(int fildes, const char *
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
break;
#else /* !HAS_LZMA_H */
@@ -1190,6 +1251,7 @@ FILE * fdzopen(int fildes, const char *
if (ret->_fileno < 0)
ret->_fileno = 0;
# endif
+ cookie->stdio = ret;
}
# else /* !HAS_LZMADEC_H */
errno = ENOTSUP;

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:868857b7398b600b2198f78d8829aa9d3c9ccd26aa1268a8a420c00761cfc544
size 21354

3
libzio-1.02.tar.bz2 Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6c3e2bac2461add50c58e68d6c94a7d448658ddee9776c07b97b6c8204dc068b
size 21490

View File

@ -1,3 +1,11 @@
-------------------------------------------------------------------
Thu Feb 19 21:52:33 UTC 2015 - p.drouand@gmail.com
- Update to version 1.02
* Fixed version: handle fseek() correct for bzip2 and lzma/xz
- Spec file cleanup
- Remove libzio-1.00.dif; fixed on upstream release
-------------------------------------------------------------------
Tue Apr 16 07:55:53 UTC 2013 - mmeister@suse.com

View File

@ -1,7 +1,7 @@
#
# spec file for package libzio
#
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -18,7 +18,7 @@
Name: libzio
%define lname libzio1
Version: 1.00
Version: 1.02
Release: 0
Summary: A Library for Accessing Compressed Text Files
License: GPL-2.0+
@ -26,31 +26,15 @@ Group: System/Libraries
Url: http://libzio.sourceforge.net/
Source: http://downloads.sourceforge.net/project/%{name}/%{name}/%{version}/%{name}-%{version}.tar.bz2
Source1: baselibs.conf
# PATCH-FIX-UPSTREAM: handle fseek() correct for bzip2 and lzma/xz
Patch0: libzio-1.00.dif
BuildRequires: libbz2-devel
BuildRequires: zlib-devel
%if %suse_version <= 1110
BuildRequires: lzma
BuildRequires: lzma-devel
%else
BuildRequires: xz
BuildRequires: xz-devel
%endif
# bug437293
%ifarch ppc64
Obsoletes: libzio-64bit
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
Libzio provides a wrapper function for reading or writing gzip or bzip2
files with FILE streams.
Author:
--------
Werner Fink <werner@suse.de>
%package -n %lname
Summary: A Library for Accessing Compressed Text Files
Group: System/Libraries
@ -61,33 +45,18 @@ Obsoletes: libzio <= %{version}
Libzio provides a wrapper function for reading or writing gzip or bzip2
files with FILE streams.
Author:
--------
Werner Fink <werner@suse.de>
%package devel
Summary: Libzio development files
Group: Development/Libraries/C and C++
Requires: %lname = %{version}
# bug437293
%ifarch ppc64
Obsoletes: libzio-devel-64bit
%endif
#
%description devel
Libzio development files including zio.h, the manual page fzopen(3),
and static library.
Authors:
--------
Werner Fink <werner@suse.de>
%prep
%setup -q
%patch0
%build
make %{?_smp_mflags} noweak
@ -95,11 +64,7 @@ make %{?_smp_mflags} noweak
%check
make testt
make tests
%if %suse_version <= 1110
for comp in gzip bzip2 lzma
%else
for comp in gzip bzip2 lzma xz
%endif
do
$comp -c < fzopen.3.in > fzopen.test
./testt fzopen.test | cmp fzopen.3.in -
@ -124,6 +89,6 @@ make DESTDIR=$RPM_BUILD_ROOT install libdir=%{_libdir} mandir=%{_mandir}
%{_libdir}/libzio.a
%{_libdir}/libzio.so
%{_mandir}/man3/fzopen.3*
/usr/include/zio.h
%{_includedir}/zio.h
%changelog