History log of /freebsd-current/bin/cat/cat.c
Revision Date Author Comments
# ad4f3bdf 10-May-2024 Dag-Erling Smørgrav <des@FreeBSD.org>

cat: Missed a couple.

MFC after: 3 days
Sponsored by: Klara, Inc.


# c6f9df70 09-May-2024 Dag-Erling Smørgrav <des@FreeBSD.org>

cat: Check for lack of success rather than a specific failure.

MFC after: 3 days
Sponsored by: Klara, Inc.
Reviewed by: oshogbo
Differential Revision: https://reviews.freebsd.org/D45149


# 05f530f4 14-Feb-2024 Ed Maste <emaste@FreeBSD.org>

cat: fix cap_rights_init usage

Capability rights passed to cap_rights_* are not simple bitmaks and
cannot be ORed together in general (although it will work for certain
subsets of rights).

PR: 277057
Reported by: asomers, markj


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

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


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


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

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


# 3c773cad 18-Nov-2023 Martin Matuska <mm@FreeBSD.org>

cat: fallback on EISDIR with copy_file_range(2)

The filesystem may support reading directories directly
when security.bsd.allow_read_dir is set.

MFC after: 1 week
PR: 275099


# 64c63277 28-Sep-2023 Mariusz Zaborski <oshogbo@FreeBSD.org>

cat: add CAP_SEEK capability

The copy_file_range might require that.

Reviewed by: emaste, theraven, kib, markj
Differential Revision: https://reviews.freebsd.org/D41967


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

Remove $FreeBSD$: one-line .c pattern

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


# 055f920e 08-Jul-2023 Martin Matuska <mm@FreeBSD.org>

cat: fallback on EBADF with copy_file_range(2)

When stdout is opened with O_APPEND, copy_file_range(2) fails with EBADF.


# 8113cc82 08-Jul-2023 Martin Matuska <mm@FreeBSD.org>

cat: use copy_file_range(2) with fallback to previous behavior

This allows to use special filesystem features like server-side
copying on NFS 4.2 or block cloning on OpenZFS 2.2.

Reviewed by: imp, rmacklem
Differential revision: https://reviews.freebsd.org/D40882


# 38f57faa 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

cat: ensure serrno is always set

Set serrno to errno before the loop begins for the edge case that res0
is immediately NULL.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/724


# 0614d739 20-Jan-2021 Mariusz Zaborski <oshogbo@FreeBSD.org>

cat: style nits

Pointed out by: jhb


# de57c3d8 15-Jan-2021 Mariusz Zaborski <oshogbo@FreeBSD.org>

cat: style nits


# 6e8062c8 15-Jan-2021 Mariusz Zaborski <oshogbo@FreeBSD.org>

cat: persistent errno

There is no guarantee that after close(2)/free the errno will remain
persistent. The caller of the udom_open function depends on the errno
for reporting errors.

Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D28185


# c664d8df 15-Jan-2021 Mariusz Zaborski <oshogbo@FreeBSD.org>

cat: Fix potential memory leak

This was introduced in aefe30c5437159a5399bdbc1974d6fbf40f2ba0f.


# aefe30c5 15-Jan-2021 Mariusz Zaborski <oshogbo@FreeBSD.org>

cat: capsicumize it

Reviewed by: markj, arichardson
Differential Revision: https://reviews.freebsd.org/D28083


# ed845580 06-Jan-2021 Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>

Fix all warnings emitted in `make kernel-toolchain`

With this change and D27598 make kernel-toolchain no longer emits any
warnings for me.

Reviewed By: emaste
Differential Revision: https://reviews.freebsd.org/D27599


# a33ee411 16-Jan-2020 Alex Richardson <arichardson@FreeBSD.org>

Allow building bin/cat on non-FreeBSD systems

`cat -l` is needed during the installworld phase and other system's cat
don't support that flag. To avoid portability issues when compiling on
Linux/macOS (such as the the direct access to &fp->_mbstate), we
disable the entire multibyte support when building as a boostrap tool.

Reviewed By: brooks, emaste
Differential Revision: https://reviews.freebsd.org/D13939


# 6d5343e3 07-Jan-2018 Xin LI <delphij@FreeBSD.org>

stddef.h is not used by cat.c, remove the include.


# ca23e64e 05-Jan-2018 Warner Losh <imp@FreeBSD.org>

Sanity check sysconf return value to ensure it's positive before we
use it. Use proper cast to convert long to size_t (instead of
blksize_t) to preclude sign extension issues.

CID: 1193754


# 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.


# 6d2e5f3d 21-Sep-2017 Sevan Janiyan <sevan@FreeBSD.org>

Ammend bin/cat/cat.c so the output is the same aside
from blank lines being numbered or unnumbered, depending on whether cat
was invoked with -ne or -be.

At present, when cat is invoked with -be, there is an aditional
difference that the '$' on blank lines is placed on the far left of the
output.

Discussed in bug 210607.

While here, revert the workaround from r304035 which skipped the unit test for
this issue previously.

PR: 210607
Submitted by: myself
Reviewed by: bdrewery
Obtained from: NetBSD
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D12432


# 4be62405 09-Aug-2017 Ed Maste <emaste@FreeBSD.org>

cat: fix build with -DNO_UDOM_SUPPORT

Sponsored by: The FreeBSD Foundation


# 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


# 2aa6b16f 15-Sep-2016 Andrey A. Chernov <ache@FreeBSD.org>

Implement multibyte encoding support for -v with fallback

MFC after: 7 days


# 64c7af10 03-Oct-2015 Sean Bruno <sbruno@FreeBSD.org>

Initialize fd to -1 so that gcc doesn't emit an unitialized warning.


# 19271eb4 03-Oct-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Make GCC happy


# 1c9fbb5a 02-Oct-2015 Hiroki Sato <hrs@FreeBSD.org>

Use getaddrinfo() to fill struct sockaddr_un. It now supports
SOCK_DGRAM and SOCK_SEQPACKET in addition to SOCK_STREAM.


# 4c766481 11-Jan-2014 Adrian Chadd <adrian@FreeBSD.org>

Close the newly-created FD if the pathname is too long.

Coverity: CID 1007204
Sponsored by: Netflix, Inc.


# e99f8bc0 23-Apr-2013 Eitan Adler <eadler@FreeBSD.org>

- Add the __dead2 attribute since it is a function that never returns
- Add an empty line in usage() according to style(9)

PR: bin/177076
Submitted by: Fernando <fernando.apesteguia@gmail.com>
Approved by: cperciva (mentor)


# aece80a2 29-Jan-2013 Brooks Davis <brooks@FreeBSD.org>

Add -l option to cat(1). This option causes cat(1) to use fcntl(2) to
set an exclusive advisory lock on stdout. This will be used to guarantee
orderly writing to METALOG.

Sponsored by: DARPA, AFRL
Obtained from: NetBSD (mason)


# e3481b29 20-Jul-2012 Jaakko Heinonen <jh@FreeBSD.org>

Use proper error message when fstat(2) fails on stdout.

PR: bin/159746
Submitted by: Alex K.


# 67bf019b 20-Jul-2012 Jaakko Heinonen <jh@FreeBSD.org>

style(9).


# f9d4afb4 31-Oct-2011 Ed Schouten <ed@FreeBSD.org>

Put some static keywords in the source code.

For these simple utilities, it doesn't harm to make all global variables
static. In fact, this allows the compiler to perform better forms of
optimisation and analysis.


# 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.


# e9cbc9a7 30-Oct-2008 Ivan Voras <ivoras@FreeBSD.org>

Teach cat(1) and cp(1) to use a larger buffer if enough memory is present
in the system. A simple heuristics is used to detect what is "enough"
memory: if number of physmem pages is greater than 32k (equalling 128 MB
on machines with 4 kB pages).

Typical immediate result of these changes is reduction in context switches
and the goal is to increase efficiency by using large buffers:
before: /usr/bin/time -hlp cat file1 > file2
...
163 voluntary context switches
11194 involuntary context switches
after: /usr/bin/time -hlp ./cat file1 > file2
...
417 voluntary context switches
272 involuntary context switches

Reviewed by: hackers@ (no objections to earlier version of cat patch)
Approved by: gnn (mentor)
MFC after: 4 months


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

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


# 9ddb49cb 10-Jan-2005 Warner Losh <imp@FreeBSD.org>

/*- or .\"- or #- to begin license clauses.


# 2c61418d 19-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Use warn() instead of perror().


# 6195fb41 06-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 0d22cdf0 30-Apr-2003 David E. O'Brien <obrien@FreeBSD.org>

We have to hide copyright[] for gcc33. :-(


# 9d32ecfc 23-Oct-2002 Mark Murray <markm@FreeBSD.org>

Be consistent about declaring a function "static", and consistent
about the type of argv.


# 9f82c1d3 31-Jul-2002 Mark Murray <markm@FreeBSD.org>

Give lint a small bit of help.


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

Consistently use __FBSDID


# 88485b4a 28-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Avoid truncating the pathname to UNIX Domain Sockets with snprintf(),
giving a more sensible warning when the (relatively meagre) sun_path
limit is exceeded.


# ca2be2ff 14-Jun-2002 Juli Mallett <jmallett@FreeBSD.org>

Use an usage() rather than doing the fprintf inside option parsing.


# bf5f0c44 13-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Print the "$" symbol on blank lines when the -s and -e options are used
together.

Obtained from: OpenBSD (millert, Denis Afonin)


# 99cc2240 13-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Remove bogus "-" operand from usage message. There is no restriction on
where it may be placed, it is treated the same as the file arguments.


# 9afa09cd 22-Feb-2002 Mark Murray <markm@FreeBSD.org>

Fix warnings inspired by lint, a commercial lint and WARNS=4.


# 78a3801d 01-Feb-2002 Warner Losh <imp@FreeBSD.org>

Drag cat(1) kicking and screaming into the late 1980's:

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.

Approved by: arch@, new style(9)


# 43e09ab2 26-Sep-2001 Ruslan Ermilov <ru@FreeBSD.org>

WARNSify.


# 1b00c916 26-Sep-2001 Ruslan Ermilov <ru@FreeBSD.org>

The "cat - -" feature was broken by the last commit.
Restore the code that avoided closing and reopening
stdin. This is also required by POSIX. As a bonus,
enable multiple stdin reads with the -benstv flags,
by resetting the EOF condition on stdin.


# cbf2d71f 14-Sep-2001 Matthew Dillon <dillon@FreeBSD.org>

Give /bin/cat the ability to connect to and read unix-domain sockets

MFC after: 1 week


# cafefe8c 24-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Include missing header files which define functions for which gcc has
builtins (e.g., exit, strcmp).


# 2192b407 14-Apr-2000 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>

Sync us up to OpenBSD's cat.1 v1.18 and cat.c v1.9.

This gets rid of a bogus cast of NULL in setbuf().
Lets us know the buffer malloc failed.

Reworks the manpage a bit to make it more mdoc(7) compliant, adds
examples.


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

$Id$ -> $FreeBSD$


# d1762d1f 13-Sep-1998 Warner Losh <imp@FreeBSD.org>

Fix minor style bugs noticed by the Bruce Filter.[tm]

Bruce-Filter-By: bde


# a5da0999 10-Sep-1998 Warner Losh <imp@FreeBSD.org>

Silence -Wall -W -Wkitchen-sink. Use ssize_t in preference to int,
make a char * const that should have been. Use new style function
declaration for main. Mostly a Bruce Filter[tm] test commit.


# 12f93eb9 13-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Restore Lite2 sccsids by removing `const'. Improve documentation a little.
Suggested by: Bruce


# 4c95995f 06-May-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm, .An and other cosmetics. Add rcsid. Remove unused #inc.


# c4694019 01-Jul-1997 Bruce Evans <bde@FreeBSD.org>

Import Lite2's src/bin. All files in src/bin are off the vendor branch,
so this doesn't change the active versions.


# 93ef08af 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# b97fa2ef 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 890acb95 13-Dec-1996 Steve Price <steve@FreeBSD.org>

Merge Lite2 mods and -Wall cleaning.


# 3043192b 30-Sep-1996 Andrey A. Chernov <ache@FreeBSD.org>

Activate LC_CTYPE locale and additionly use !isprint() for 8bit characters


# 8d72a3d7 28-Sep-1996 Warner Losh <imp@FreeBSD.org>

Merge in the NetBSD changes to cat.c. These appear to have come from
the 4.4 lite 2 tape as well. There are now only two diffs between
NetBSD's cat and FreeBSD's cat:
getopt return value is -1 on NetBSD and EOF on FreeBSD.
NetBSD has added setlocale calls before anything else.


# 001aff9f 02-Oct-1995 Bruce Evans <bde@FreeBSD.org>

Fix exit status. `cat no-such-file >/dev/null' exited with status 0.
This has been broken since cat's own err() function was sloppily
replaced by the library functions warn() and err().


# 89730b29 23-Sep-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# 4b88c807 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite bin Sources