summaryrefslogtreecommitdiff
path: root/lib/libz
diff options
context:
space:
mode:
authormrg <mrg@NetBSD.org>2004-01-29 13:08:19 +0000
committermrg <mrg@NetBSD.org>2004-01-29 13:08:19 +0000
commit42d0909cf94bd8a2fb5b599c3d7e72f2cd9570aa (patch)
tree5f17a3702229d2918d2d6e4fdcaae35cff4770c4 /lib/libz
parenta57f9a6ca5c1597da42f62431d0c7704fe3f619e (diff)
add two functions to zlib: gzopenfull() and gzdopenfull() that both take
additional "const char *savename" and "u_int32_t mtime" parameters that are written out into the gzip header in the mtime field and as the original filename.
Diffstat (limited to 'lib/libz')
-rw-r--r--lib/libz/gzio.c63
-rw-r--r--lib/libz/shlib_version4
-rw-r--r--lib/libz/zlib.336
-rw-r--r--lib/libz/zlib.h11
4 files changed, 96 insertions, 18 deletions
diff --git a/lib/libz/gzio.c b/lib/libz/gzio.c
index 529ea5f327d..3b2725d38dd 100644
--- a/lib/libz/gzio.c
+++ b/lib/libz/gzio.c
@@ -1,4 +1,4 @@
-/* $NetBSD: gzio.c,v 1.19 2003/03/18 20:51:24 jdolecek Exp $ */
+/* $NetBSD: gzio.c,v 1.20 2004/01/29 13:08:19 mrg Exp $ */
/* gzio.c -- IO on .gz files
* Copyright (C) 1995-2002 Jean-loup Gailly.
@@ -7,10 +7,10 @@
* Compile this file with -DNO_DEFLATE to avoid the compression code.
*/
-/* @(#) $Id: gzio.c,v 1.19 2003/03/18 20:51:24 jdolecek Exp $ */
+/* @(#) $Id: gzio.c,v 1.20 2004/01/29 13:08:19 mrg Exp $ */
#include <sys/cdefs.h>
-__RCSID("$NetBSD: gzio.c,v 1.19 2003/03/18 20:51:24 jdolecek Exp $");
+__RCSID("$NetBSD: gzio.c,v 1.20 2004/01/29 13:08:19 mrg Exp $");
#include <stdio.h>
@@ -58,7 +58,8 @@ typedef struct gz_stream {
} gz_stream;
-local gzFile gz_open __P((const char *path, const char *mode, int fd));
+local gzFile gz_open __P((const char *path, const char *mode, int fd,
+ u_int32_t mtime, const char *name));
local int do_flush __P((gzFile file, int flush));
local int get_byte __P((gz_stream *s));
local void check_header __P((gz_stream *s));
@@ -75,10 +76,12 @@ local uLong getLong __P((gz_stream *s));
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR).
*/
-local gzFile gz_open (path, mode, fd)
+local gzFile gz_open (path, mode, fd, mtime, name)
const char *path;
const char *mode;
int fd;
+ u_int32_t mtime;
+ const char *name;
{
int err;
int level = Z_DEFAULT_COMPRESSION; /* compression level */
@@ -167,13 +170,23 @@ local gzFile gz_open (path, mode, fd)
/* Write a very simple .gz header:
*/
fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
- Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
+ Z_DEFLATED, name ? ORIG_NAME : 0,
+ mtime & 0xff,
+ (mtime >> 8) & 0xff,
+ (mtime >> 16) & 0xff,
+ (mtime >> 24) & 0xff,
+ 0 /*xflags*/, OS_CODE);
s->startpos = 10L;
/* We use 10L instead of ftell(s->file) to because ftell causes an
* fflush on some systems. This version of the library doesn't use
* startpos anyway in write mode, so this initialization is not
* necessary.
*/
+ if (name) {
+ size_t len = strlen(name) + 1;
+ fwrite(name, len, 1, s->file);
+ s->startpos += len;
+ }
} else {
check_header(s); /* skip the .gz header */
s->startpos = (ftell(s->file) - s->stream.avail_in);
@@ -183,29 +196,55 @@ local gzFile gz_open (path, mode, fd)
}
/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing, with name and mtime
+ information stored.
+*/
+gzFile ZEXPORT gzopenfull (path, mode, name, mtime)
+ const char *path;
+ const char *mode;
+ const char *name;
+ u_int32_t mtime;
+{
+ return gz_open (path, mode, -1, mtime, name);
+}
+
+/* ===========================================================================
Opens a gzip (.gz) file for reading or writing.
*/
gzFile ZEXPORT gzopen (path, mode)
const char *path;
const char *mode;
{
- return gz_open (path, mode, -1);
+ return gz_open (path, mode, -1, 0, NULL);
}
/* ===========================================================================
Associate a gzFile with the file descriptor fd. fd is not dup'ed here
- to mimic the behavio(u)r of fdopen.
+ to mimic the behavio(u)r of fdopen, setting file name / mtime.
*/
-gzFile ZEXPORT gzdopen (fd, mode)
+gzFile ZEXPORT gzdopenfull (fd, mode, name, mtime)
int fd;
const char *mode;
+ const char *name;
+ u_int32_t mtime;
{
- char name[20];
+ char fname[20];
if (fd < 0) return (gzFile)Z_NULL;
- sprintf(name, "<fd:%d>", fd); /* for debugging */
+ sprintf(fname, "<fd:%d>", fd); /* for debugging */
- return gz_open (name, mode, fd);
+ return gz_open (fname, mode, fd, mtime, name);
+}
+
+/* ===========================================================================
+ Associate a gzFile with the file descriptor fd. fd is not dup'ed here
+ to mimic the behavio(u)r of fdopen.
+*/
+gzFile ZEXPORT gzdopen (fd, mode)
+ int fd;
+ const char *mode;
+{
+ return gzdopenfull (fd, mode, NULL, 0);
}
/* ===========================================================================
diff --git a/lib/libz/shlib_version b/lib/libz/shlib_version
index e4ff5327247..3d59f784085 100644
--- a/lib/libz/shlib_version
+++ b/lib/libz/shlib_version
@@ -1,5 +1,5 @@
-# $NetBSD: shlib_version,v 1.6 2002/05/29 20:07:44 christos Exp $
+# $NetBSD: shlib_version,v 1.7 2004/01/29 13:08:19 mrg Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=0
-minor=3
+minor=4
diff --git a/lib/libz/zlib.3 b/lib/libz/zlib.3
index a8b757e8eba..cef7ae8296c 100644
--- a/lib/libz/zlib.3
+++ b/lib/libz/zlib.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: zlib.3,v 1.1 2003/10/03 18:46:22 wiz Exp $
+.\" $NetBSD: zlib.3,v 1.2 2004/01/29 13:08:19 mrg Exp $
.\" $OpenBSD: zlib.3,v 1.1 2003/09/25 09:12:09 jmc Exp $
.\"
.\" Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
@@ -22,7 +22,7 @@
.\" Converted to mdoc format for the OpenBSD project
.\" by Jason McIntyre <jmc@openbsd.org>
.\"
-.Dd September 17, 2003
+.Dd January 29, 2004
.Dt ZLIB 3
.Os
.Sh NAME
@@ -76,8 +76,12 @@
.Ft gzFile
.Fn gzopen "const char *path" "const char *mode"
.Ft gzFile
+.Fn gzopenfull "const char *path" "const char *mode" "const char *savename" "u_int32_t mtime"
+.Ft gzFile
.Fn gzdopen "int fd" "const char *mode"
.Ft int
+.Fn gzdopenfull "int fd" "const char *mode" "const char *savename" "u_int32_t mtime"
+.Ft int
.Fn gzsetparams "gzFile file" "int level" "int strategy"
.Ft int
.Fn gzread "gzFile file" "voidp buf" "unsigned len"
@@ -1225,6 +1229,20 @@ error is
.Dv Z_MEM_ERROR ) .
.It Xo
.Fa gzFile
+.Fn gzopenfull "const char *path" "const char *mode" "const char *savename" "u_int32_t mtime" ;
+.Xc
+.Pp
+The
+.Fn gzopenfull
+function performs the same function as
+.Fn gzopen
+as well as setting the
+.Ar mtime
+in the gzip header and saving
+.Ar savename
+as the original file name in the gzip header.
+.It Xo
+.Fa gzFile
.Fn gzdopen "int fd" "const char *mode" ;
.Xc
.Pp
@@ -1257,6 +1275,20 @@ returns
.Dv NULL
if there was insufficient memory to allocate the (de)compression state.
.It Xo
+.Fa gzFile
+.Fn gzdopenfull "int fd" "const char *mode" "const char *savename" "u_int32_t mtime" ;
+.Xc
+.Pp
+The
+.Fn gzdopenfull
+function performs the same function as
+.Fn gzdopen
+as well as setting the
+.Ar mtime
+in the gzip header and saving
+.Ar savename
+as the original file name in the gzip header.
+.It Xo
.Fa int
.Fn gzsetparams "gzFile file" "int level" "int strategy" ;
.Xc
diff --git a/lib/libz/zlib.h b/lib/libz/zlib.h
index cadcac59a9c..db23db5e4a3 100644
--- a/lib/libz/zlib.h
+++ b/lib/libz/zlib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: zlib.h,v 1.14 2003/03/22 17:23:09 christos Exp $ */
+/* $NetBSD: zlib.h,v 1.15 2004/01/29 13:08:19 mrg Exp $ */
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.4, March 11th, 2002
@@ -655,6 +655,8 @@ ZEXTERN int ZEXPORT uncompress __P((Bytef *, uLongf *, const Bytef *, uLong));
typedef voidp gzFile;
ZEXTERN gzFile ZEXPORT gzopen __P((const char *, const char *));
+ZEXTERN gzFile ZEXPORT gzopenfull __P((const char *, const char *,
+ const char *, u_int32_t));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
@@ -668,9 +670,13 @@ ZEXTERN gzFile ZEXPORT gzopen __P((const char *, const char *));
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
- zlib error is Z_MEM_ERROR). */
+ zlib error is Z_MEM_ERROR).
+
+ The full version sets name and timestamp information as well. */
ZEXTERN gzFile ZEXPORT gzdopen __P((int, const char *));
+ZEXTERN gzFile ZEXPORT gzdopenfull __P((int, const char *, const char *,
+ u_int32_t));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
@@ -681,6 +687,7 @@ ZEXTERN gzFile ZEXPORT gzdopen __P((int, const char *));
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
+ The full version sets name and timestamp information as well.
*/
ZEXTERN int ZEXPORT gzsetparams __P((gzFile, int, int));