From nobody Sat Nov 14 14:30:43 2026 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 4jRc440rGRz718v1 for ; Sat, 14 Nov 2026 14:30:44 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jRc4357Nyz4JP1 for ; Sat, 14 Nov 2026 14:30:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794666643; 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=0RqrCqP60GGXyXxSfoE2HedgToLIZj+sDDeBrIYHFes=; b=hI+072brsaE0SZrMoXL+NA9X5TzeSzGwaSLFrlhAotWfpIdD5kWoK6uTa7zAFYl5pMcH3r Rsui6DRuQMnqRPKFe4+l91QDIRW4pdG2kLpNZfokIxhUJe8HyKhdVkJTrsWlC7VaOB2MKI HC7lb/jrort7eaxNsszEeWlk0CekVoHlivlj5z24/GIbeZMxv6sepsu5g0z7r26+cDklO7 4A1Qmx3fIm+JW7c1AwDSx5nNawceV1ZnWQ8eT+yxPOdxqvtR4/YrpOF4Qja765XLHkOPiW jpERqUszY7ppMyDjk1vH3kNDKE2Ank271unQ4gKk1F7Hg+GZQUTls8jD964zbA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794666643; b=S92XmTjM63H/7vo6PwN6fqvYiwKNLl002FO9IM+/UeX/fGaFLKePphh0x7kpq/2lPp8BWW BxMEW0wbIPNVc+UBWtUkkedht8r9rONEb/Mm/Q5xpkBp5Wq+rDNvgYoGZk0sbVFmC+tmre tSCOrORaxVmfl/Nk351rSrYskOugz2jgcXZ1Sif2rR57yK/+tn/aMIHPtAGhZMVSyfT8kS jVhTko/loqTYDm91QRO4DesumODTbj6WuYj/bWqe1jxdI6UHKy/u+ZEFfao7exT5EEB7T1 bUw/q9YWrHH1d3a5yFUIrANqJpoAhGGAfwn4Btctt26ReWPIyWv4X4Fv/GM5+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794666643; 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=0RqrCqP60GGXyXxSfoE2HedgToLIZj+sDDeBrIYHFes=; b=IHLHxNn8fyevaZsm5bjSt0udDHSpMRBShgtMoH+XRkEQ7jvLX3RTZcM8N0YM9ZKxoWDyn1 JerLZM4fW0uFrVAfFZJyW0Gw/FNq/aJ9Rolj5WD3g+cfTsaqbobw7N3ymRigVsD5zH5Lsg dSIL6oE9P1MC8wfj2iV2iqIAlOSileg7d7LFgFxyHKCQDFLoSnBNIcaMVV1ZtD+AFS69ac ZdYwbtxl+gwfAlSF1kB+CSL+itqijBRd5kzp0YjDJTAeLCbAYCDZWjHpNV203Spoi1rJzK O4iaqw2n0heR7KzhplnDFRBJzBbEhrXGUnDsMxE+VJEI2A0EsD36fxf6hZlKJg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jRc433jGDzP0Q for ; Sat, 14 Nov 2026 14:30:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id d669 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 14 Nov 2026 14:30:43 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ryan Moeller Subject: git: 70046933082e - main - libutil: Introduce fhexdump(3) List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmoeller X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 70046933082e2e22646fb270320f070b59957b72 Auto-Submitted: auto-generated Date: Sat, 14 Nov 2026 14:30:43 +0000 Message-Id: <6af87093.d669.575c73d3@gitrepo.freebsd.org> The branch main has been updated by rmoeller: URL: https://cgit.FreeBSD.org/src/commit/?id=70046933082e2e22646fb270320f070b59957b72 commit 70046933082e2e22646fb270320f070b59957b72 Author: Ryan Moeller AuthorDate: 2026-11-12 04:57:53 +0000 Commit: Ryan Moeller CommitDate: 2026-11-14 14:26:26 +0000 libutil: Introduce fhexdump(3) Extend hexdump(3) to write to a given stream. Reviewed by: kevans Approved by: kevans (mentor) Differential Revision: https://reviews.freebsd.org/D61177 --- lib/libutil/Makefile | 1 + lib/libutil/Symbol.map | 1 + lib/libutil/hexdump.3 | 19 +++++++++++++++---- lib/libutil/hexdump.c | 29 +++++++++++++++++------------ lib/libutil/libutil.h | 2 ++ 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile index d54d9af38a34..b5582c775958 100644 --- a/lib/libutil/Makefile +++ b/lib/libutil/Makefile @@ -42,6 +42,7 @@ MAN+= fparseln.3 MAN+= ftime.3 MAN+= getlocalbase.3 MAN+= hexdump.3 +MLINKS+=hexdump.3 fhexdump.3 MAN+= humanize_number.3 MAN+= kinfo_getallproc.3 MAN+= kinfo_getfile.3 diff --git a/lib/libutil/Symbol.map b/lib/libutil/Symbol.map index fbd10769b2a0..c3c326c453ed 100644 --- a/lib/libutil/Symbol.map +++ b/lib/libutil/Symbol.map @@ -130,6 +130,7 @@ FBSD_1.8 { }; FBSD_1.9 { + fhexdump; trimdomain; }; diff --git a/lib/libutil/hexdump.3 b/lib/libutil/hexdump.3 index e5a18e201bbd..7adfd00f5149 100644 --- a/lib/libutil/hexdump.3 +++ b/lib/libutil/hexdump.3 @@ -26,23 +26,30 @@ .\" (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 May 8, 2020 +.Dd November 14, 2026 .Dt HEXDUMP 3 .Os .Sh NAME +.Nm fhexdump , .Nm hexdump -.Nd "dump a block of bytes to standard out in hexadecimal form" +.Nd "dump a block of bytes to a stream in hexadecimal form" .Sh LIBRARY .Lb libutil .Sh SYNOPSIS +.In stdio.h .In libutil.h .Ft void -.Fn hexdump "void *ptr" "int length" "const char *hdr" "int flags" +.Fn hexdump "const void *ptr" "int length" "const char *hdr" "int flags" +.Ft void +.Fn fhexdump "FILE *stream" "const void *ptr" "int length" "const char *hdr" "int flags" .Sh DESCRIPTION The .Fn hexdump function prints an array of bytes to standard out in hexadecimal form, -along with the ASCII representation of the bytes, if possible. +along with the ASCII representation of the bytes, if possible; +.Fn fhexdump +writes to the given output +.Fa stream . By default, each line of output will start with an offset count, followed by 16 hexadecimal values, followed by 16 ASCII characters. .Bl -tag -width indent @@ -88,6 +95,10 @@ The .Fn hexdump function first appeared in .Fx 6.4 . +The +.Fn fhexdump +function first appeared in +.Fx 16.0 . .Sh AUTHORS This manual page was written by .An Scott Long . diff --git a/lib/libutil/hexdump.c b/lib/libutil/hexdump.c index 26ec2df66fcb..3afdbb61fae6 100644 --- a/lib/libutil/hexdump.c +++ b/lib/libutil/hexdump.c @@ -35,11 +35,11 @@ */ #include -#include #include +#include void -hexdump(const void *ptr, int length, const char *hdr, int flags) +fhexdump(FILE *fp, const void *ptr, int length, const char *hdr, int flags) { int i, j, k; int cols; @@ -59,35 +59,40 @@ hexdump(const void *ptr, int length, const char *hdr, int flags) cp = ptr; for (i = 0; i < length; i+= cols) { if (hdr != NULL) - printf("%s", hdr); + fprintf(fp, "%s", hdr); if ((flags & HD_OMIT_COUNT) == 0) - printf("%04x ", i); + fprintf(fp, "%04x ", i); if ((flags & HD_OMIT_HEX) == 0) { for (j = 0; j < cols; j++) { k = i + j; if (k < length) - printf("%c%02x", delim, cp[k]); + fprintf(fp, "%c%02x", delim, cp[k]); else - printf(" "); + fprintf(fp, " "); } } if ((flags & HD_OMIT_CHARS) == 0) { - printf(" |"); + fprintf(fp, " |"); for (j = 0; j < cols; j++) { k = i + j; if (k >= length) - printf(" "); + fprintf(fp, " "); else if (cp[k] >= ' ' && cp[k] <= '~') - printf("%c", cp[k]); + fprintf(fp, "%c", cp[k]); else - printf("."); + fprintf(fp, "."); } - printf("|"); + fprintf(fp, "|"); } - printf("\n"); + fprintf(fp, "\n"); } } +void +hexdump(const void *ptr, int length, const char *hdr, int flags) +{ + fhexdump(stdout, ptr, length, hdr, flags); +} diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index 17e4f1fba247..54c298d1ae21 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -152,6 +152,8 @@ int uu_lock_txfr(const char *_ttyname, pid_t _pid); * files upon which they depend have been included. */ #ifdef _STDIO_H_ +void fhexdump(FILE *_fp, const void *_ptr, int _length, const char *_hdr, + int _flags); char *fparseln(FILE *_fp, size_t *_len, size_t *_lineno, const char _delim[3], int _flags); #endif