Page MenuHomeFreeBSD

D61177.1794647148.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D61177.1794647148.diff

diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -42,6 +42,7 @@
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
--- a/lib/libutil/Symbol.map
+++ b/lib/libutil/Symbol.map
@@ -130,6 +130,7 @@
};
FBSD_1.9 {
+ fhexdump;
trimdomain;
};
diff --git a/lib/libutil/hexdump.3 b/lib/libutil/hexdump.3
--- 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 October 28, 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 libutil.h
.Ft void
.Fn hexdump "void *ptr" "int length" "const char *hdr" "int flags"
+.In stdio.h
+.Ft void
+.Fn fhexdump "FILE * restrict stream" "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 @@
.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
--- a/lib/libutil/hexdump.c
+++ b/lib/libutil/hexdump.c
@@ -35,11 +35,12 @@
*/
#include <sys/types.h>
-#include <libutil.h>
#include <stdio.h>
+#include <libutil.h>
void
-hexdump(const void *ptr, int length, const char *hdr, int flags)
+fhexdump(FILE * __restrict fp, const void *ptr, int length, const char *hdr,
+ int flags)
{
int i, j, k;
int cols;
@@ -59,35 +60,40 @@
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
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -152,6 +152,8 @@
* 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

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 14, 9:05 AM (2 h, 45 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41719522
Default Alt Text
D61177.1794647148.diff (3 KB)

Event Timeline