diff options
Diffstat (limited to 'lib/libz')
-rw-r--r-- | lib/libz/FREEBSD-upgrade | 14 | ||||
-rw-r--r-- | lib/libz/Makefile | 85 | ||||
-rw-r--r-- | lib/libz/Makefile.depend | 15 | ||||
-rw-r--r-- | lib/libz/Symbol.map | 114 | ||||
-rw-r--r-- | lib/libz/Versions.def | 22 | ||||
-rw-r--r-- | lib/libz/zopen.3 | 106 | ||||
-rw-r--r-- | lib/libz/zopen.c | 63 |
7 files changed, 419 insertions, 0 deletions
diff --git a/lib/libz/FREEBSD-upgrade b/lib/libz/FREEBSD-upgrade new file mode 100644 index 000000000000..1b034f86f211 --- /dev/null +++ b/lib/libz/FREEBSD-upgrade @@ -0,0 +1,14 @@ +Original distribution from http://zlib.net/. Currently, only trivial +changes were made to support build of libsa and to suppress certain +compiler warnings, we upstream our local changes whenever they would +benefit other consumers. + +To update: + 1) Unpack vendor sources into a clean directory. + 2) Import onto the vendor area. + 3) Merge the vendor tree to sys/contrib/zlib, which contains a stripped down + version of upstream source, resolve any conflicts. + 4) Double check zconf.h, zlib.pc, and Symbol.map to make sure that we + have the required changes. Test universe and commit them. + +delphij@FreeBSD.org diff --git a/lib/libz/Makefile b/lib/libz/Makefile new file mode 100644 index 000000000000..6a135158e134 --- /dev/null +++ b/lib/libz/Makefile @@ -0,0 +1,85 @@ +# +# + +PACKAGE= runtime +LIB= z +SHLIBDIR?= /lib +SHLIB_MAJOR= 6 +MAN= zlib.3 zopen.3 +MLINKS+= zopen.3 zdopen.3 + +ZLIBSRC= ${SRCTOP}/sys/contrib/zlib + +.PATH: ${ZLIBSRC} + +#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 +#CFLAGS=-g -DDEBUG +#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ +# -Wstrict-prototypes -Wmissing-prototypes + +CFLAGS+= -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I${.CURDIR} + +WARNS?= 3 + +CLEANFILES+= example.o example foo.gz minigzip.o minigzip + +SRCS+= adler32.c +SRCS+= compress.c +SRCS+= crc32.c +SRCS+= deflate.c +SRCS+= gzclose.c +SRCS+= gzlib.c +SRCS+= gzread.c +SRCS+= gzwrite.c +SRCS+= infback.c +SRCS+= inffast.c +SRCS+= inflate.c +SRCS+= inftrees.c +SRCS+= trees.c +SRCS+= uncompr.c +SRCS+= zutil.c + +# Wrapper relies on FreeBSD-specific fpos_t representation and non-portable +# funopen. Not needed for bootstrapping, so just disable it. +.if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING) +SRCS+= zopen.c +.endif + +.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64" +CFLAGS+= -DUNALIGNED_OK +.endif + +VERSION_DEF= ${.CURDIR}/Versions.def +SYMBOL_MAPS= ${.CURDIR}/Symbol.map + +INCS= zconf.h zlib.h + +.PATH: ${ZLIBSRC}/test + +ZLIB_VERSION!= sed -n '/define.*ZLIB_VERSION/{s,[^0-9.],,gp;q;}' ${ZLIBSRC}/zlib.h + +zlib.pc: zlib.pc.in + sed -e 's,@prefix@,/usr,g ; \ + s,@exec_prefix@,$${prefix},g ; \ + s,@libdir@,${LIBDIR},g ; \ + s,@sharedlibdir@,${SHLIBDIR},g ; \ + s,@includedir@,${INCLUDEDIR},g ; \ + s,@VERSION@,${ZLIB_VERSION},g ;' \ + ${.ALLSRC} > ${.TARGET} + +minigzip: all minigzip.o + $(CC) -o minigzip minigzip.o -L. -lz + +example: all example.o + $(CC) -o example example.o -L. -lz + +test: example minigzip + (export LD_LIBRARY_PATH=. ; ./example ) + (export LD_LIBRARY_PATH=. ; \ + echo hello world | ./minigzip | ./minigzip -d ) + +PCFILES= zlib.pc + +.include <bsd.lib.mk> + +CWARNFLAGS+= ${NO_WDEPRECATED_NON_PROTOTYPE} ${NO_WSTRICT_PROTOTYPES} diff --git a/lib/libz/Makefile.depend b/lib/libz/Makefile.depend new file mode 100644 index 000000000000..6ef78fac5cbf --- /dev/null +++ b/lib/libz/Makefile.depend @@ -0,0 +1,15 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + include/xlocale \ + lib/${CSU_DIR} \ + lib/libc \ + lib/libcompiler_rt \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/libz/Symbol.map b/lib/libz/Symbol.map new file mode 100644 index 000000000000..7bfe7cceda77 --- /dev/null +++ b/lib/libz/Symbol.map @@ -0,0 +1,114 @@ +/* + */ + +ZLIB_1.2.12 { + crc32_combine_gen; + crc32_combine_gen64; + crc32_combine_op; +}; + +ZLIB_1.2.9 { + inflateCodesUsed; + inflateValidate; + uncompress2; + gzfread; + gzfwrite; + deflateGetDictionary; + adler32_z; + crc32_z; +}; + +ZLIB_1.2.7.1 { + inflateGetDictionary; + gzvprintf; +}; + +ZLIB_1.2.7.0 { + deflatePending; + deflateResetKeep; + gzgetc_; + inflateResetKeep; +}; + +ZLIB_1.2.4.0 { + adler32; + adler32_combine; + adler32_combine64; + compress; + compress2; + compressBound; + crc32; + crc32_combine; + crc32_combine64; + deflate; + deflateBound; + deflateCopy; + deflateEnd; + deflateInit2_; + deflateInit_; + deflateParams; + deflatePrime; + deflateReset; + deflateSetDictionary; + deflateSetHeader; + deflateTune; + get_crc_table; + gzbuffer; + gzclearerr; + gzclose; + gzclose_r; + gzclose_w; + gzdirect; + gzdopen; + gzeof; + gzerror; + gzflush; + gzgetc; + gzgets; + gzoffset; + gzoffset64; + gzopen; + gzopen64; + gzprintf; + gzputc; + gzputs; + gzread; + gzrewind; + gzseek; + gzseek64; + gzsetparams; + gztell; + gztell64; + gzungetc; + gzwrite; + inflate; + inflateBack; + inflateBackEnd; + inflateBackInit_; + inflateCopy; + inflateEnd; + inflateGetHeader; + inflateInit2_; + inflateInit_; + inflateMark; + inflatePrime; + inflateReset; + inflateReset2; + inflateSetDictionary; + inflateSync; + inflateSyncPoint; + inflateUndermine; + uncompress; + zError; + zlibCompileFlags; + zlibVersion; +}; + +FBSD_1.2 { + zopen; +}; + +FBSD_1.6 { + zdopen; +}; + diff --git a/lib/libz/Versions.def b/lib/libz/Versions.def new file mode 100644 index 000000000000..2ee0106b5bfe --- /dev/null +++ b/lib/libz/Versions.def @@ -0,0 +1,22 @@ + +ZLIB_1.2.4.0 { +}; + +ZLIB_1.2.7.0 { +} ZLIB_1.2.4.0; + +ZLIB_1.2.7.1 { +} ZLIB_1.2.7.0; + +ZLIB_1.2.9 { +} ZLIB_1.2.7.1; + +ZLIB_1.2.12 { +} ZLIB_1.2.9; + +FBSD_1.2 { +} ZLIB_1.2.4.0; + +FBSD_1.6 { +} FBSD_1.2; + diff --git a/lib/libz/zopen.3 b/lib/libz/zopen.3 new file mode 100644 index 000000000000..d76fb378676f --- /dev/null +++ b/lib/libz/zopen.3 @@ -0,0 +1,106 @@ +.\" Copyright (c) 2014 Xin LI <delphij@FreeBSD.org> +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd December 6, 2018 +.Dt ZOPEN 3 +.Os +.Sh NAME +.Nm zopen +.Nd open a gzip compressed stream +.Sh LIBRARY +.Lb libz +.Sh SYNOPSIS +.Ft FILE * +.Fn zopen "const char *path" "const char *mode" +.Ft FILE * +.Fn zdopen "int fd" "const char *mode" +.Sh DESCRIPTION +The +.Fn zopen +function opens a gzip file whose name is the string pointed to by +.Fa path +and returns a stream which can be used to access the uncompressed contents +of the file. +The +.Fn zdopen +variant takes a gzip file referenced by the file descriptor +.Fa fd , +analogous to +.Xr fdopen 3 . +They are wrappers around +.Xr zlib 3 +and the standard stream I/O APIs. +.Pp +The argument +.Fa mode +has the same meaning as it does in +.Xr fopen 3 . +.Pp +The +.Fn zopen +and +.Fn zdopen +functions will associate the read, write, seek and close +functions of +.Xr zlib 3 +with the returned stream. +.Sh RETURN VALUES +Upon successful completion +.Fn zopen +and +.Fn zdopen +return a +.Tn FILE +pointer. +Otherwise, +.Dv NULL +is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +In addition to the errors documented for +.Xr fopen 3 +and +.Xr fdopen 3 , +the functions may also fail for: +.Bl -tag -width Er +.It Bq Er ENOMEM +Insufficient memory is available. +.El +.Sh COMPATIBILITY +The implementation of +.Fn zopen +function first appeared in +.Nx 1.6 +and +.Fx 4.5 . +.Fn zdopen +first appeared in +.Fx 13.0 . +These functions may not be portable to systems other than +.Fx . +.Sh SEE ALSO +.Xr fdopen 3 , +.Xr fopen 3 , +.Xr funopen 3 , +.Xr zlib 3 diff --git a/lib/libz/zopen.c b/lib/libz/zopen.c new file mode 100644 index 000000000000..faef346f7ce5 --- /dev/null +++ b/lib/libz/zopen.c @@ -0,0 +1,63 @@ +/* + * Public domain stdio wrapper for libz, written by Johan Danielsson. + */ + +#include <sys/cdefs.h> +#include <stdio.h> +#include <zlib.h> + +FILE *zopen(const char *fname, const char *mode); +FILE *zdopen(int fd, const char *mode); + +/* convert arguments */ +static int +xgzread(void *cookie, char *data, int size) +{ + return gzread(cookie, data, size); +} + +static int +xgzwrite(void *cookie, const char *data, int size) +{ + return gzwrite(cookie, (void*)data, size); +} + +static int +xgzclose(void *cookie) +{ + return gzclose(cookie); +} + +static fpos_t +xgzseek(void *cookie, fpos_t offset, int whence) +{ + return gzseek(cookie, (z_off_t)offset, whence); +} + +FILE * +zopen(const char *fname, const char *mode) +{ + gzFile gz = gzopen(fname, mode); + if(gz == NULL) + return NULL; + + if(*mode == 'r') + return (funopen(gz, xgzread, NULL, xgzseek, xgzclose)); + else + return (funopen(gz, NULL, xgzwrite, xgzseek, xgzclose)); +} + +FILE * +zdopen(int fd, const char *mode) +{ + gzFile gz; + + gz = gzdopen(fd, mode); + if (gz == NULL) + return (NULL); + + if (*mode == 'r') + return (funopen(gz, xgzread, NULL, xgzseek, xgzclose)); + else + return (funopen(gz, NULL, xgzwrite, xgzseek, xgzclose)); +} |