Hello community,
here is the log from the commit of package libzio
checked in at Fri Dec 7 20:12:12 CET 2007.
--------
--- libzio/libzio.changes 2007-03-26 11:23:21.000000000 +0200
+++ /mounts/work_src_done/STABLE/libzio/libzio.changes 2007-12-07 17:43:32.311771000 +0100
@@ -1,0 +2,5 @@
+Fri Dec 7 17:42:49 CET 2007 - werner@suse.de
+
+- Add support for streams on file descriptors
+
+-------------------------------------------------------------------
Old:
----
libzio-0.4.tar.bz2
New:
----
libzio-0.5.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ libzio.spec ++++++
--- /var/tmp/diff_new_pack.u29356/_old 2007-12-07 20:11:24.000000000 +0100
+++ /var/tmp/diff_new_pack.u29356/_new 2007-12-07 20:11:24.000000000 +0100
@@ -1,5 +1,5 @@
#
-# spec file for package libzio (Version 0.4)
+# spec file for package libzio (Version 0.5)
#
# Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany.
# This file and all modifications and additions to the pristine
@@ -11,12 +11,15 @@
# norootforbuild
Name: libzio
-BuildRequires: libbz2-devel zlib-devel
-License: GNU General Public License (GPL)
+BuildRequires: zlib-devel
+%if %suse_version > 1020
+BuildRequires: libbz2-devel
+%endif
+License: GPL v2 or later
Group: System/Libraries
-Autoreqprov: on
-Version: 0.4
-Release: 11
+AutoReqProv: on
+Version: 0.5
+Release: 1
Summary: A Library for Accessing Compressed Text Files
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source: libzio-%{version}.tar.bz2
@@ -36,7 +39,7 @@
Summary: libzio development files
Group: System/Libraries
Requires: libzio = %{version}
-Autoreqprov: on
+AutoReqProv: on
%description devel
libzio development files
@@ -54,9 +57,11 @@
%build
make
make testt
+make tests
for comp in gzip bzip2; do
$comp -c < fzopen.3.in > fzopen.test
./testt fzopen.test | cmp fzopen.3.in -
+ cat fzopen.test | ./testt fzopen.test $comp | cmp fzopen.3.in -
done
%install
@@ -71,7 +76,7 @@
%files
%defattr(-,root,root)
%{_libdir}/libzio.so.0
-%{_libdir}/libzio.so.0.4
+%{_libdir}/libzio.so.0.5
%files devel
%defattr(-,root,root)
@@ -82,6 +87,8 @@
/usr/include/zio.h
%changelog
+* Fri Dec 07 2007 - werner@suse.de
+- Add support for streams on file descriptors
* Mon Mar 26 2007 - rguenther@suse.de
- Split off libzio-devel.
* Sat Mar 24 2007 - aj@suse.de
++++++ libzio-0.4.tar.bz2 -> libzio-0.5.tar.bz2 ++++++
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/fzopen.3.in new/libzio-0.5/fzopen.3.in
--- old/libzio-0.4/fzopen.3.in 2006-12-20 19:06:57.000000000 +0100
+++ new/libzio-0.5/fzopen.3.in 2007-12-07 17:39:15.000000000 +0100
@@ -12,17 +12,26 @@
.OS SuSE Linux
.SH NAME
fzopen \- stream open functions on compressed files
+.br
+fdzopen \- stream open functions on compressed files
.SH SYNOPSIS
.\"
.B #include
.sp
.BI "FILE *fzopen (const char *" path ", const char *" mode );
+.br
+.BI "FILE *fdzopen (int " fildes ", const char *" mode ", const char *" what );
.SH DESCRIPTION
The
.B fzopen
function opens the compressed file whose name is the string to by
.I path
and associates a stream with it.
+The
+.B fdopen
+function associates a stream for the existing files descriptor
+.I fildes
+for a compressed file.
.PP
The argument
.I mode
@@ -40,8 +49,25 @@
.BR w1 - 9
Just like above but provides also the compression level.
.PP
+The argument
+.I what
+of the function
+.B fdzopen
+specifies the underlying compression mehtod which should be used:
+.TP
+.BR g , z
+The file descriptor points to a gziped file.
+.TP
+.BR b
+The file descriptor points to a bzip2ed file.
+.TP
+.BR Z
+The file descriptor points to a file in LZW format.
+.PP
Note that
.B fzopen
+and
+.B fdzopen
can only open a compressed text file for reading
.B or
writing, but
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/lzw.h new/libzio-0.5/lzw.h
--- old/libzio-0.4/lzw.h 2006-12-20 19:06:57.000000000 +0100
+++ new/libzio-0.5/lzw.h 2007-12-07 17:39:15.000000000 +0100
@@ -118,5 +118,6 @@
} LZW_t;
extern LZW_t *openlzw(const char * __restrict, const char * __restrict);
+extern LZW_t *dopenlzw(int fildes, const char * __restrict);
extern ssize_t readlzw(LZW_t * __restrict, char * __restrict, const size_t);
extern void closelzw(LZW_t * __restrict);
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/Makefile new/libzio-0.5/Makefile
--- old/libzio-0.4/Makefile 2006-12-20 19:06:56.000000000 +0100
+++ new/libzio-0.5/Makefile 2007-12-07 17:39:15.000000000 +0100
@@ -8,7 +8,7 @@
CFLAGS = $(RPM_OPT_FLAGS) -pipe -Wall -D_GNU_SOURCE -D_REENTRANT $(LARGE)
CC = gcc
MAJOR = 0
-MINOR = 4
+MINOR = 5
VERSION = $(MAJOR).$(MINOR)
libdir = /usr/lib
@@ -21,6 +21,7 @@
zioP.h \
zio.h.in \
testt.c \
+ tests.c \
lzw.h \
unlzw.c \
fzopen.3.in
@@ -70,7 +71,7 @@
ln -sf libzio.so.$(MAJOR) $(DESTDIR)$(libdir)/libzio.so
clean:
- rm -f *.a *.so* testt zio.h
+ rm -f *.a *.so* testt tests zio.h
rm -rf obj/ obs/
rm -f libzio-$(VERSION).tar.gz
@@ -82,3 +83,6 @@
testt: testt.c libzio.a
$(CC) $(CFLAGS) -o $@ $^ -lz -lbz2
+
+tests: tests.c libzio.a
+ $(CC) $(CFLAGS) -o $@ $^ -lz -lbz2
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/README new/libzio-0.5/README
--- old/libzio-0.4/README 2006-12-20 19:06:56.000000000 +0100
+++ new/libzio-0.5/README 2007-12-07 17:39:15.000000000 +0100
@@ -17,6 +17,11 @@
FILE * file = fzopen("myfile.gz", "r");
+or
+
+ int fd = open("myfile.gz", O_RDONLY);
+ FILE * file = fdzopen(fd, "r", "g");
+
together with linking the resulting program with -lzio _and_
`-lz'. For bzip2 files clearly the libbz2 with `-lbz2' has
to used at linkage time.
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/tests.c new/libzio-0.5/tests.c
--- old/libzio-0.4/tests.c 1970-01-01 01:00:00.000000000 +0100
+++ new/libzio-0.5/tests.c 2007-12-07 17:39:15.000000000 +0100
@@ -0,0 +1,28 @@
+#include
+#include
+#include
+#include
+#include "zio.h"
+
+int main(int argc, char *argv[])
+{
+ FILE *file;
+ char line[1024];
+ size_t len;
+
+ if (!(file = fdzopen(fileno(stdin), "r", argc > 1 ? argv[1] : "g"))) {
+ fprintf(stderr, "%s\n", strerror(errno));
+ return 1;
+ }
+
+ while ((len = fread(line, sizeof(char), sizeof (line), file))) {
+ size_t ret = fwrite(line, sizeof(char), len, stdout);
+ if ((ret != len) && ferror(stdout)) {
+ clearerr(stdout);
+ }
+ }
+
+ fclose(file);
+
+ return 0;
+}
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/unlzw.c new/libzio-0.5/unlzw.c
--- old/libzio-0.4/unlzw.c 2006-12-20 19:06:57.000000000 +0100
+++ new/libzio-0.5/unlzw.c 2007-12-07 17:39:15.000000000 +0100
@@ -49,7 +49,7 @@
if (len < 0) {
if (errno == EINTR)
continue;
- perror(in->ifname);
+ perror(__FUNCTION__);
break;
}
if (len == 0)
@@ -153,6 +153,18 @@
*/
LZW_t *openlzw(const char * path, const char *mode)
{
+ int fildes;
+ if (!mode || *mode != 'r')
+ goto out;
+ if ((fildes = open(path, O_RDONLY)) < 0)
+ goto out;
+ return dopenlzw(fildes, mode);
+out:
+ return (LZW_t*)0;
+}
+
+LZW_t *dopenlzw(int fildes, const char *mode)
+{
LZW_t *in = (LZW_t*)0;
uint8_t magic[2];
sigset_t sigmask, oldmask;
@@ -174,9 +186,7 @@
goto err;
if ((in->tab_prefix = (uint16_t*)malloc(sizeof(uint16_t)*(1<<(BITS)))) == (uint16_t*)0)
goto err;
- if ((in->ifname = strdup(path)) == (char*)0)
- goto err;
- if ((in->ifd = open(in->ifname, O_RDONLY)) < 0)
+ if ((in->ifd = fildes) < 0)
goto err;
if ((in->stack = (uint8_t*)malloc(STACK_SIZE)) == (uint8_t*)0)
@@ -217,14 +227,14 @@
if ((in->n.maxbits & LZW_RESERVED) != 0) {
fprintf(stderr, "%s: warning, unknown flags 0x%x\n",
- in->ifname, in->n.maxbits & LZW_RESERVED);
+ __FUNCTION__, in->n.maxbits & LZW_RESERVED);
}
in->n.maxbits &= BIT_MASK;
in->n.maxmaxcode = MAXCODE(in->n.maxbits);
if (in->n.maxbits > BITS) {
fprintf(stderr, "%s: compressed with %d bits, can only handle %d bits\n",
- in->ifname, in->n.maxbits, BITS);
+ __FUNCTION__, in->n.maxbits, BITS);
goto err;
}
@@ -259,7 +269,6 @@
if (in->uc) free(in->uc);
if (in->stack) free(in->stack);
if (in->ifd >= 0) close(in->ifd);
- if (in->ifname) free(in->ifname);
if (in->tab_prefix) free(in->tab_prefix);
if (in->tab_suffix) free(in->tab_suffix);
if (in->d_buf) free(in->d_buf);
@@ -295,7 +304,7 @@
if (in->rsize < 0) {
if (errno == EINTR)
continue;
- perror(in->ifname);
+ perror(__FUNCTION__);
break;
}
if (in->rsize == 0)
@@ -324,7 +333,7 @@
if (in->n.oldcode == -1) {
if (256 <= in->n.code)
- fprintf(stderr, "%s: corrupt input.\n", in->ifname);
+ fprintf(stderr, "%s: corrupt input.\n", __FUNCTION__);
in->outbuf[in->outpos++] = (uint8_t)(in->n.finchar = (int)(in->n.oldcode=in->n.code));
continue;
}
@@ -358,7 +367,7 @@
in->bytes_out += (off_t)in->outpos;
in->outpos = 0;
}
- fprintf(stderr, "%s: corrupt input.\n", in->ifname);
+ fprintf(stderr, "%s: corrupt input.\n", __FUNCTION__);
}
*--in->n.stackp = (uint8_t)in->n.finchar;
in->n.code = in->n.oldcode;
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/zio.c new/libzio-0.5/zio.c
--- old/libzio-0.4/zio.c 2006-12-20 19:06:56.000000000 +0100
+++ new/libzio-0.5/zio.c 2007-12-07 17:39:15.000000000 +0100
@@ -12,23 +12,9 @@
* Author: Werner Fink
*/
-#if ! defined USE_PIPE_4LZW
-# define USE_PIPE_4LZW 0
-#endif
-
#include "zioP.h"
#include "zio.h"
-#if defined(USE_PIPE_4LZW) && (USE_PIPE_4LZW == 1)
-# include
-# include
-# include
- typedef struct LZW_s {
- int lfd;
- pid_t lpid;
- } LZW_t;
-#else
-# include "lzw.h"
-#endif
+#include "lzw.h"
static ssize_t zread(void *cookie, char *buf, size_t count)
{
@@ -92,15 +78,7 @@
static ssize_t lzwread(void *cookie, char *buf, size_t count)
{
-#if defined(USE_PIPE_4LZW) && (USE_PIPE_4LZW == 1)
- ssize_t ret = 0;
- do {
- ret = read(((LZW_t*)cookie)->lfd, buf, count);
- } while ((ret < 0) && (errno == EINTR));
- return ret;
-#else
return readlzw((LZW_t*)cookie, buf, count);
-#endif
}
static ssize_t lzwwrite(void *cookie, const char *buf, size_t count)
@@ -117,20 +95,8 @@
static int lzwclose(void *cookie)
{
-#if defined(USE_PIPE_4LZW) && (USE_PIPE_4LZW == 1)
- int wstatus, status = close(((LZW_t*)cookie)->lfd);
- pid_t wpid;
- do {
- wpid = waitpid(((LZW_t*)cookie)->lpid, &wstatus, 0);
- } while ((wpid < 0) && (errno == EINTR));
- if ((wpid < 0) || (wstatus != 0))
- status = -1;
- free(cookie);
- return (status >= 0) ? 0 : EOF;
-#else
closelzw((LZW_t*)cookie);
return 0;
-#endif
}
__extension__
@@ -272,62 +238,140 @@
case 'Z':
{
LZW_t *cookie;
-#if defined(USE_PIPE_4LZW) && (USE_PIPE_4LZW == 1)
- int pfd[2];
-
if (*mode != 'r') {
errno = ENOTSUP;
goto out;
}
- if ((cookie = (LZW_t*)malloc(sizeof(LZW_t))) == (LZW_t*)0)
+ if (!(cookie = openlzw(ext, mode))) {
+ if (!errno)
+ errno = ENOMEM;
+ goto out;
+ }
+
+ if (!(ret = fopencookie(cookie, check, iolzw))) {
+ closelzw(cookie);
+ errno = EINVAL;
goto out;
+ }
+#ifndef LIBIO_IS_FIXED
+ if (ret->_fileno < 0)
+ ret->_fileno = 0;
+#endif
+ }
+ break;
+ case 'b':
+ {
+ BZFILE* cookie = (BZFILE*)0;
+
+ if (&BZ2_bzopen == NULL) {
+ errno = ENOSYS;
+ goto out;
+ }
- if (pipe(pfd) < 0) {
+ if (!(cookie = BZ2_bzopen(ext, mode))) {
if (!errno)
- errno = EINVAL;
+ errno = ENOMEM;
goto out;
}
- switch ((cookie->lpid = fork())) {
- case -1:
- close(pfd[0]);
- close(pfd[1]);
- goto out;
- case 0:
- (void)signal(SIGINT, SIG_DFL);
- (void)signal(SIGQUIT, SIG_DFL);
- (void)signal(SIGSEGV, SIG_DFL);
- (void)signal(SIGTERM, SIG_DFL);
-
- close(pfd[0]);
- if (pfd[1] != 1) {
- if (dup2(pfd[1], 1) < 0)
- exit(127);
- close(pfd[1]);
- }
-
- execl("/bin/gzip", "gzip", "-dfcq", ext, (char*)0);
- exit(127);
- default:
- close(pfd[1]);
- cookie->lfd = pfd[0];
- break;
+ if (!(ret = fopencookie(cookie, check, iobz))) {
+ BZ2_bzclose(cookie);
+ errno = EINVAL;
+ goto out;
}
+#ifndef LIBIO_IS_FIXED
+ if (ret->_fileno < 0)
+ ret->_fileno = 0;
+#endif
+ }
+ break;
+ default:
+ ret = fopen(ext, mode);
+ break;
+ }
- if (!(ret = fopencookie(cookie, check, iolzw))) {
- close(pfd[0]);
- free(cookie);
+out:
+ if (check)
+ free(check);
+ if (ext && ext != path)
+ free(ext);
+
+ return ret;
+}
+
+FILE * fdzopen(int fildes, const char * mode, const char *what)
+{
+ FILE * ret = (FILE *)0;
+ char * check = (char*)0;
+ size_t n = 0;
+ unsigned int i;
+
+ 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;
+ }
+
+ switch (*what) {
+ case 'g':
+ case 'z': /* Is this correct? Old gzip magic */
+ {
+ gzFile cookie = (gzFile)0;
+
+ if (&gzdopen == NULL) {
+ errno = ENOSYS;
+ goto out;
+ }
+
+ if (!(cookie = gzdopen(fildes, mode))) {
+ if (!errno)
+ errno = ENOMEM;
+ goto out;
+ }
+
+ if (!(ret = fopencookie(cookie, check, ioz))) {
+ gzclose(cookie);
errno = EINVAL;
goto out;
}
-#else
+#ifndef LIBIO_IS_FIXED
+ if (ret->_fileno < 0)
+ ret->_fileno = 0;
+#endif
+ }
+ break;
+ case 'Z':
+ {
+ LZW_t *cookie;
if (*mode != 'r') {
errno = ENOTSUP;
goto out;
}
- if (!(cookie = openlzw(ext, mode))) {
+ if (!(cookie = dopenlzw(fildes, mode))) {
if (!errno)
errno = ENOMEM;
goto out;
@@ -338,7 +382,6 @@
errno = EINVAL;
goto out;
}
-#endif
#ifndef LIBIO_IS_FIXED
if (ret->_fileno < 0)
ret->_fileno = 0;
@@ -349,12 +392,12 @@
{
BZFILE* cookie = (BZFILE*)0;
- if (&BZ2_bzopen == NULL) {
+ if (&BZ2_bzdopen == NULL) {
errno = ENOSYS;
goto out;
}
- if (!(cookie = BZ2_bzopen(ext, mode))) {
+ if (!(cookie = BZ2_bzdopen(fildes, mode))) {
if (!errno)
errno = ENOMEM;
goto out;
@@ -372,15 +415,12 @@
}
break;
default:
- ret = fopen(ext, mode);
+ ret = fdopen(fildes, mode);
break;
}
out:
if (check)
free(check);
- if (ext && ext != path)
- free(ext);
-
return ret;
}
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/libzio-0.4/zio.h.in new/libzio-0.5/zio.h.in
--- old/libzio-0.4/zio.h.in 2006-12-20 19:06:57.000000000 +0100
+++ new/libzio-0.5/zio.h.in 2007-12-07 17:39:15.000000000 +0100
@@ -23,7 +23,8 @@
* This function can open a gziped file for reading OR writing, but
* NOT both (not `+' possible) NOR can it open for appending (no `a').
*/
-extern FILE *fzopen __P((__const char *__restrict path, __const char *__restrict mode));
+extern FILE *fzopen __P((__const char *__restrict, __const char *__restrict));
+extern FILE *fdzopen __P((int, __const char *__restrict mode, __const char *__restrict));
#ifdef __cplusplus
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org