History log of /freebsd-current/usr.bin/hexdump/display.c
Revision Date Author Comments
# e23954bd 03-Jan-2024 Ricardo Branco <rbranco@suse.de>

hexdump: Do not trust st_size if it equals zero.

Fix for hexdump -s not being able to skip files residing in
pseudo-filesystems that advertise a zero size value.

Historically, many pseudofs-based filesystems (e.g., procfs) report
a va_size of 0 for numerous files classified as regular files.
Typically, the contents of these files are generated on demand
from kernel data as sbuf(9) strings at the time they are read.
Accurately reporting the size of these files is challenging, as it
often involves generating their contents. These pseudofs implementations
frequently report the size as 0. This is a historical behavior and also
aligns with Linux behavior. To maintain compatibility, we have chosen
to preserve the existing behavior and address it in the userland
application, rather than modifying it in the kernel (by updating the
correct value for va_size).

PR: bin/276106
MFC after: 1 week


# 5e3934b1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# d1016568 08-Jun-2023 Xin LI <delphij@FreeBSD.org>

hexdump: Partial lines cannot be repetitions of earlier lines.

When checking for repetitions of earlier lines, we compare the
first nread bytes of the line against the saved line. However,
when we read a partial line, it should never be treated as a
repetition of an earlier line, even if the first bytes match.

This change fixes a bug where a partial line could be
incorrectly identified as a repetition of an earlier line.

Reported-by: Mark Adler <madler@alumni.caltech.edu>
PR: 118723
Reviewed-by: emaste
MFC-after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D40471


# 1232c788 07-Jun-2023 Xin LI <delphij@FreeBSD.org>

od(1): Fix skip value handling

POSIX defines -j as the number of bytes that od(1) should skip over the
concatenated input files. The existing code tries to implement this behavior
by checking if the current address was smaller than the skip value. However,
this is not correct, because we adjust both the skip value and the address
at the same time when we do fseeko (when file is seekable) or getchar (when
file is not seekable).

This commit fixes the problem by expecting the skip value to be zero upon
return of next(). If the condition is not satisfied, a diagnostic message
will be issued.

Reported-by: Mohamed Akram <mohd.akram@outlook.com>
Reviewed-by: emaste
PR: 271832
MFC-after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D40446


# 37e3f5b2 07-Dec-2001 Ben Harris <bjh21@netbsd.org>

Enable support for printing 8-byte integers. For some reason, most of the
code for this was present, but disabled.
This is required for POSIX compliance on platforms with 8-byte longs.

Obtained-From: NetBSD
PR: 238586
Reported-By: Mohamed Akram <mohd.akram@outlook.com>
MFC after: 2 weeks


# 272144ab 29-Jul-2021 Poul-Henning Kamp <phk@FreeBSD.org>

hexdump: Flush stdout after '*' (repeat) lines.

The canonical annoying example being: hexdump < /dev/zero | less


# 7672a014 19-Jun-2018 Mariusz Zaborski <oshogbo@FreeBSD.org>

Convert `cap_enter() < 0 && errno != ENOSYS` to `caph_enter() < 0`.

No functional change intended.


# df7b0169 04-Jan-2018 Kyle Evans <kevans@FreeBSD.org>

hexdump(1): Speed up -s flag on devices

Using the -s flag on devices is extraordinarily slow due to using fseek(3) a
little too conservatively. Address this by using fseek on character/block
devices as well, falling back to getchar(3) only if we fail to seek or we're
operating on tape drives, where fseek may succeed while not actually being
supported.

PR: 86485
Submitted by: arundel (originally; modified since then)
Reviewed by: cem
Differential Revision: https://reviews.freebsd.org/D10939


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# e47ea033 12-Jun-2017 Ed Maste <emaste@FreeBSD.org>

hexdump: actually enter capability mode on last file

Reviewed by: cem, Kyle Evans
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D10897


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 327240c7 15-Dec-2016 Conrad Meyer <cem@FreeBSD.org>

hexdump(1): First cut capsicumification

For now, only enter the sandbox for the last file processed (including
stdin for zero-argument mode).

Sandboxing all inputs will require a little restructuring of the
program.

Feedback by: emaste@ (earlier versions)
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D7915


# daa1a379 14-Feb-2016 Kevin Lo <kevlo@FreeBSD.org>

Fix a bug that caused nothing to be skipped when skipping exactly the
number of bytes present in a regular file was requested.

Obtained from: OpenBSD


# c3210060 26-Apr-2015 Jilles Tjoelker <jilles@FreeBSD.org>

hexdump: Don't use uninitialized struct stat.


# b3608ae1 03-Jan-2012 Ed Schouten <ed@FreeBSD.org>

Replace index() and rindex() calls with strchr() and strrchr().

The index() and rindex() functions were marked LEGACY in the 2001
revision of POSIX and were subsequently removed from the 2008 revision.
The strchr() and strrchr() functions are part of the C standard.

This makes the source code a lot more consistent, as most of these C
files also call into other str*() routines. In fact, about a dozen
already perform strchr() calls.


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 821df508 12-Dec-2009 Xin LI <delphij@FreeBSD.org>

Revert most part of 200420 as requested, as more review and polish is
needed.


# 6f2d3221 11-Dec-2009 Xin LI <delphij@FreeBSD.org>

Remove unneeded header includes from usr.bin/ except contributed code.

Tested with: make universe


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 9a1e2d06 03-Aug-2004 Tim J. Robbins <tjr@FreeBSD.org>

In next(), ensure that 'done' is set in the case when a file cannot
be opened, to avoid trying to read standard input after already closing
it, which resulted in EBADF errors.


# e95e2344 28-Jul-2004 Alexander Kabaev <kan@FreeBSD.org>

Do not predeclare __inline functions, this makes no sense and generates
a warning with gcc 3.4.x.


# aae01d24 22-Jul-2004 Johan Karlsson <johan@FreeBSD.org>

display.c:
- 'savech' is only used if it is set a few lines above where
it is used, initialize it to silence warning.

- 'length' is either -1 or greater than 0, hence it is safe to cast it
to unsigned when comparing it here.

odsyntax.c:
- 'p' is assigned either (*argvp)[0] or (*argvp)[1] which both are
char *. 'num' and 'end' are assigned values based on 'p'.
Hence use char * instead of unsigned char * for these variables.

'&end' as the second argument to strtoll does not need to be casted
to char** any more.

This solves a
'dereferencing type-punned pointer will break strict-aliasing rules'
warning when compiling with -O2.

parse.c:
- 'prec' is only used when sokay == USEPREC and sokay = USEPREC
when 'prec' is assigned. Hence 'prec' is not used uninitialized,
initialize it to silence warning.

- The code involving 'nextpr' is hard to follow, but I belive
'nextpr' will not be used unless it is initialized.
Anyway, IF 'nextpr' is used uninitialized it is better to
get a consistant error (seg fault, when dereferencing a NULL pointer)
than potentially accessing some random memory.

The above changes makes hexdump WARNS=6 clean even when compiled with
-O2. Hence bump WARNS to keep it clean.

Tested by: CFLAGS='-O2 -pipe' make universe


# 40ccfb31 10-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Add POSIX-style support for multibyte characters to od(1): the 'c'
conversion interprets input bytes as multibyte sequences and displays
printable characters in the area corresponding to their first byte.
The remaining bytes are shown as "**".


# f4ac32de 04-Sep-2002 David Malone <dwmalone@FreeBSD.org>

ANSIify function definitions.
Add some constness to avoid some warnings.
Remove use register keyword.
Deal with missing/unneeded extern/prototypes.
Some minor type changes/casts to avoid warnings.

Reviewed by: md5


# 8bd89d7e 19-Jul-2002 Mark Murray <markm@FreeBSD.org>

s/inline/__inline/


# e026a48c 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use FBSDID


# cf021af2 17-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Overhaul hexdump's od syntax code to handle the -s -A -j -N -t options that
SUSv3 requires and give od a proper manual page.

PR: 36783


# 1b50831d 17-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Declare variables that were extern'd in multiple places in hexdump.h.

PR: 36783


# 82866376 17-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Add support for printing long doubles.

PR: 36783


# cf45dcc8 16-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Print signed single-byte decimal integers correctly instead of implicitly
converting them to unsigned bytes.

PR: 36783


# f1bb2cd2 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# 66da3588 07-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Slightly more efficient fix to the const problem.


# c38cc743 01-Dec-2001 Mark Murray <markm@FreeBSD.org>

WARNS=2 fixups.


# 7a27e657 01-Sep-2001 Andrey A. Chernov <ache@FreeBSD.org>

File positions are off_t nowdays, not long, so:
strtol -> strtoll
fseek -> fseeko

NOTE: that fseek not works for >long offsets files per POSIX:

[EOVERFLOW] For fseek( ), the resulting file offset would be a value which
cannot be represented correctly in an object of type long.


# ac3c230c 24-Jul-2001 David E. O'Brien <obrien@FreeBSD.org>

Remove the misnamed `emalloc' and replace its uses with the calloc (along
with error checking) that it actually was.


# 3d3f014f 10-Jul-2000 Kris Kennaway <kris@FreeBSD.org>

Oops, missed another printf() invocation with no format string.


# 32d9afb6 10-Jul-2000 Kris Kennaway <kris@FreeBSD.org>

Don't call printf() with no format string.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# b001517f 12-Dec-1998 Matthew Dillon <dillon@FreeBSD.org>

PR: bin/9016

Fix bug with od/hd/hexdump. "*" lines are supposed to indicate one or
duplicates of the previous line, but a small file with less then 16
characters of zeros in it will be falsy identified as a repeat of
the (non-existant) previous line. i.e. the first line of output winds
up being a "*". Added a bit of code to handle the degenerate 'there is
no previous line' case for the first line.


# 10731702 10-Jul-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3) instead of local redefinition, incorporate `hd' in usage str.


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources