From nobody Sun Apr 03 22:33:19 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CB2F01A4F924; Sun, 3 Apr 2022 22:33:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KWpb35Jlwz4Twj; Sun, 3 Apr 2022 22:33:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649025199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AXt87IsdcJZP3rKGR9vzBux7wH5g6ejBnTCBnRF1+5Q=; b=fo5F/YA2+a04/+Ozsn3WuyYVtT5ORqUwIoJfheRZazyfeOHgTad9mNrIQY1RoPI/RLu3sW UjKR9gZ3a8ErADNeTgY3WD9HIS7iiTJ4h7oeCTVW8MadzbzwBVfY7c1INh66XsxUg6arDw HiR+kl18FkXCQmLX/VSkA4v/jMLpswSfvjYcvOT4WXxV/2XmkCgPgYDmB8i1f51v5wqm6/ +kK4ewRNCTj2XdPvXHtWBvW2SQ+c63yZyE03BhLtESv/MZUFrb8pQlmkQE7pufQvYlPRZ/ fbWrfPuNMCkrSUPSwtkHq+cdEQ7hLcrRDfw/4Z1Xh2eHXKkT/YJh1HeKJ8auzw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 95FD82607E; Sun, 3 Apr 2022 22:33:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 233MXJn1074808; Sun, 3 Apr 2022 22:33:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 233MXJ1K074807; Sun, 3 Apr 2022 22:33:19 GMT (envelope-from git) Date: Sun, 3 Apr 2022 22:33:19 GMT Message-Id: <202204032233.233MXJ1K074807@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Xin LI Subject: git: 61a2e7a442f7 - stable/12 - Add zdopen(3) to complement zopen(3). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: delphij X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 61a2e7a442f795dab5de1789c040fe7d97b74a5b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649025199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AXt87IsdcJZP3rKGR9vzBux7wH5g6ejBnTCBnRF1+5Q=; b=k1sDkYFgIzZMSqnY/AMHPWy5G3ALgd3HzWq2jSAT53IttyUnByuX6EQi9BLeC3G01gueDf By+EifycZZ/cQheQhZpF/HYSm5ShYcxKaOTpXiu4uszMQncSNEpchDVp0voakIsT2FBfrS wn4iJqEco0/oE4GTbQuGn4T1gqUUJzqxvSQTq607RLqo0GhsiRSz/v5NhOfFnPTDOSxvWp iyL/KQuG2UWtbI+c+GS1OU2yhayDUvemczq3COH0hYwCFmPDwI+a79caHKl/IgNil14suy ptfkkhE9puVwenXSRhAoEsDdWHRzu9vTEEGTrbptgwAmFtSiWfsZeZTxgntNIA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649025199; a=rsa-sha256; cv=none; b=dj9I5bHlYDo5aSwCuykDe7M4tJ7Zd2LUMhG1wjV5nxwlWqisidzaGCuJCfackgRdhoWKKX lLG48sidZbb6debrkVSJEd72QLlS0rBZ8zoccnT2VHSegfNa/4b0L0qjnQDxzI5HrUVtT3 w/neRskJHsKmLCe/xqQgD4loVW/NMWgusxksnlt4123e+m4XVSnKT1WPv2wjMtLJvASJkB pvcDUWz801xgMjjNqNHLqUvRSMHsTfkSG33piF+Izc/uNFf8+p985JmQ4LrEcBd0H2bH1/ MZ/Zr0QeFV4OJZiQyp1VaqXzWMEkX9vBQmI+JlGgEpfgYAZi3mEA+GHsKaCHdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by delphij: URL: https://cgit.FreeBSD.org/src/commit/?id=61a2e7a442f795dab5de1789c040fe7d97b74a5b commit 61a2e7a442f795dab5de1789c040fe7d97b74a5b Author: Mark Johnston AuthorDate: 2018-12-06 20:03:06 +0000 Commit: Xin LI CommitDate: 2022-04-03 22:32:44 +0000 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 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D18456 (cherry picked from commit 8e2a46c8bd361395add649440758880c1e3da3ee) --- lib/libz/Makefile | 1 + lib/libz/Symbol.map | 4 ++++ lib/libz/Versions.def | 3 +++ lib/libz/zopen.3 | 57 +++++++++++++++++++++++++++++++-------------------- lib/libz/zopen.c | 16 +++++++++++++++ 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/lib/libz/Makefile b/lib/libz/Makefile index 81526179e2d0..ef3ec038f6f5 100644 --- a/lib/libz/Makefile +++ b/lib/libz/Makefile @@ -7,6 +7,7 @@ LIB= z SHLIBDIR?= /lib SHLIB_MAJOR= 6 MAN= zlib.3 zopen.3 +MLINKS+= zopen.3 zdopen.3 ZLIBSRC= ${SRCTOP}/sys/contrib/zlib diff --git a/lib/libz/Symbol.map b/lib/libz/Symbol.map index 92b02b56d0eb..0a91537272c1 100644 --- a/lib/libz/Symbol.map +++ b/lib/libz/Symbol.map @@ -103,6 +103,10 @@ FBSD_1.2 { zopen; }; +FBSD_1.6 { + zdopen; +}; + ZLIBprivate_1.0 { _tr_align; _tr_flush_block; diff --git a/lib/libz/Versions.def b/lib/libz/Versions.def index d5f1816b2be8..9a67602185b8 100644 --- a/lib/libz/Versions.def +++ b/lib/libz/Versions.def @@ -15,6 +15,9 @@ ZLIB_1.2.9 { FBSD_1.2 { } ZLIB_1.2.4.0; +FBSD_1.6 { +} FBSD_1.2; + ZLIBprivate_1.0 { } ZLIB_1.2.4.0; diff --git a/lib/libz/zopen.3 b/lib/libz/zopen.3 index b56fb447a345..7677f300a8ae 100644 --- a/lib/libz/zopen.3 +++ b/lib/libz/zopen.3 @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 5, 2014 +.Dd December 6, 2018 .Dt ZOPEN 3 .Os .Sh NAME @@ -34,33 +34,44 @@ .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 -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 -and associates a stream with it. -It is a wrapper around +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 standard stream I/O APIs. +and the standard stream I/O APIs. .Pp The argument .Fa mode -have the same meaning as it does in +has the same meaning as it does in .Xr fopen 3 . .Pp The -.Nm -function will associate read, write, seek and close +.Fn zopen +and +.Fn zdopen +functions will associate the read, write, seek and close functions of .Xr zlib 3 -after successfully opened a file with -.Xr funopen 3 -so that they will be used to read or write the new stream. +with the returned stream. .Sh RETURN VALUES Upon successful completion -.Nm -returns a +.Fn zopen +and +.Fn zdopen +return a .Tn FILE pointer. Otherwise, @@ -70,26 +81,28 @@ is returned and the global variable is set to indicate the error. .Sh ERRORS In addition to the errors documented for -.Xr fopen 3 , -the -.Nm -function may also fail 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 -This implementation of -.Nm +The implementation of +.Fn zopen function first appeared in .Nx 1.6 and .Fx 4.5 . -The -.Nm -function may not be portable to systems other than +.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 index cde022dcf0e6..a6ac99166128 100644 --- a/lib/libz/zopen.c +++ b/lib/libz/zopen.c @@ -9,6 +9,7 @@ __FBSDID("$FreeBSD$"); #include FILE *zopen(const char *fname, const char *mode); +FILE *zdopen(int fd, const char *mode); /* convert arguments */ static int @@ -47,3 +48,18 @@ zopen(const char *fname, const char *mode) 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)); +}