mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-01 00:18:15 +01:00
Add zdopen(3) to complement zopen(3).
zdopen() can be used in capability mode. Update zopen.3 accordingly and fix some grammar nits while I'm here. Reviewed by: delphij MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D18456
This commit is contained in:
parent
eb687a6e70
commit
8e2a46c8bd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=341648
@ -7,6 +7,7 @@ LIB= z
|
|||||||
SHLIBDIR?= /lib
|
SHLIBDIR?= /lib
|
||||||
SHLIB_MAJOR= 6
|
SHLIB_MAJOR= 6
|
||||||
MAN= zlib.3 zopen.3
|
MAN= zlib.3 zopen.3
|
||||||
|
MLINKS+= zopen.3 zdopen.3
|
||||||
|
|
||||||
ZLIBSRC= ${SRCTOP}/contrib/zlib
|
ZLIBSRC= ${SRCTOP}/contrib/zlib
|
||||||
|
|
||||||
|
@ -103,6 +103,10 @@ FBSD_1.2 {
|
|||||||
zopen;
|
zopen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FBSD_1.6 {
|
||||||
|
zdopen;
|
||||||
|
};
|
||||||
|
|
||||||
ZLIBprivate_1.0 {
|
ZLIBprivate_1.0 {
|
||||||
_tr_align;
|
_tr_align;
|
||||||
_tr_flush_block;
|
_tr_flush_block;
|
||||||
|
@ -15,6 +15,9 @@ ZLIB_1.2.9 {
|
|||||||
FBSD_1.2 {
|
FBSD_1.2 {
|
||||||
} ZLIB_1.2.4.0;
|
} ZLIB_1.2.4.0;
|
||||||
|
|
||||||
|
FBSD_1.6 {
|
||||||
|
} FBSD_1.2;
|
||||||
|
|
||||||
ZLIBprivate_1.0 {
|
ZLIBprivate_1.0 {
|
||||||
} ZLIB_1.2.4.0;
|
} ZLIB_1.2.4.0;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd March 5, 2014
|
.Dd December 6, 2018
|
||||||
.Dt ZOPEN 3
|
.Dt ZOPEN 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -34,33 +34,44 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Ft FILE *
|
.Ft FILE *
|
||||||
.Fn zopen "const char *path" "const char *mode"
|
.Fn zopen "const char *path" "const char *mode"
|
||||||
|
.Ft FILE *
|
||||||
|
.Fn zdopen "int fd" "const char *mode"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn zopen
|
.Fn zopen
|
||||||
opens a gzip file whose name is the string pointed to by
|
function opens a gzip file whose name is the string pointed to by
|
||||||
.Fa path
|
.Fa path
|
||||||
and associates a stream with it.
|
and returns a stream which can be used to access the uncompressed contents
|
||||||
It is a wrapper around
|
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
|
.Xr zlib 3
|
||||||
and standard stream I/O APIs.
|
and the standard stream I/O APIs.
|
||||||
.Pp
|
.Pp
|
||||||
The argument
|
The argument
|
||||||
.Fa mode
|
.Fa mode
|
||||||
have the same meaning as it does in
|
has the same meaning as it does in
|
||||||
.Xr fopen 3 .
|
.Xr fopen 3 .
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Nm
|
.Fn zopen
|
||||||
function will associate read, write, seek and close
|
and
|
||||||
|
.Fn zdopen
|
||||||
|
functions will associate the read, write, seek and close
|
||||||
functions of
|
functions of
|
||||||
.Xr zlib 3
|
.Xr zlib 3
|
||||||
after successfully opened a file with
|
with the returned stream.
|
||||||
.Xr funopen 3
|
|
||||||
so that they will be used to read or write the new stream.
|
|
||||||
.Sh RETURN VALUES
|
.Sh RETURN VALUES
|
||||||
Upon successful completion
|
Upon successful completion
|
||||||
.Nm
|
.Fn zopen
|
||||||
returns a
|
and
|
||||||
|
.Fn zdopen
|
||||||
|
return a
|
||||||
.Tn FILE
|
.Tn FILE
|
||||||
pointer.
|
pointer.
|
||||||
Otherwise,
|
Otherwise,
|
||||||
@ -70,26 +81,28 @@ is returned and the global variable
|
|||||||
is set to indicate the error.
|
is set to indicate the error.
|
||||||
.Sh ERRORS
|
.Sh ERRORS
|
||||||
In addition to the errors documented for
|
In addition to the errors documented for
|
||||||
.Xr fopen 3 ,
|
.Xr fopen 3
|
||||||
the
|
and
|
||||||
.Nm
|
.Xr fdopen 3 ,
|
||||||
function may also fail for:
|
the functions may also fail for:
|
||||||
.Bl -tag -width Er
|
.Bl -tag -width Er
|
||||||
.It Bq Er ENOMEM
|
.It Bq Er ENOMEM
|
||||||
Insufficient memory is available.
|
Insufficient memory is available.
|
||||||
.El
|
.El
|
||||||
.Sh COMPATIBILITY
|
.Sh COMPATIBILITY
|
||||||
This implementation of
|
The implementation of
|
||||||
.Nm
|
.Fn zopen
|
||||||
function first appeared in
|
function first appeared in
|
||||||
.Nx 1.6
|
.Nx 1.6
|
||||||
and
|
and
|
||||||
.Fx 4.5 .
|
.Fx 4.5 .
|
||||||
The
|
.Fn zdopen
|
||||||
.Nm
|
first appeared in
|
||||||
function may not be portable to systems other than
|
.Fx 13.0 .
|
||||||
|
These functions may not be portable to systems other than
|
||||||
.Fx .
|
.Fx .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
|
.Xr fdopen 3 ,
|
||||||
.Xr fopen 3 ,
|
.Xr fopen 3 ,
|
||||||
.Xr funopen 3 ,
|
.Xr funopen 3 ,
|
||||||
.Xr zlib 3
|
.Xr zlib 3
|
||||||
|
@ -9,6 +9,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
FILE *zopen(const char *fname, const char *mode);
|
FILE *zopen(const char *fname, const char *mode);
|
||||||
|
FILE *zdopen(int fd, const char *mode);
|
||||||
|
|
||||||
/* convert arguments */
|
/* convert arguments */
|
||||||
static int
|
static int
|
||||||
@ -47,3 +48,18 @@ zopen(const char *fname, const char *mode)
|
|||||||
else
|
else
|
||||||
return (funopen(gz, NULL, xgzwrite, xgzseek, xgzclose));
|
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));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user