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.
This commit is contained in:
Jeroen Ruigrok van der Werven 2000-04-14 21:01:35 +00:00
parent 44e02d51e5
commit 2192b407ac
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=59239
2 changed files with 84 additions and 14 deletions

View File

@ -37,14 +37,13 @@
.\"
.Dd May 2, 1995
.Dt CAT 1
.Os BSD 3
.Os
.Sh NAME
.Nm cat
.Nd concatenate and print files
.Sh SYNOPSIS
.Nm cat
.Op Fl benstuv
.Op Fl
.Op Ar
.Sh DESCRIPTION
The
@ -52,8 +51,14 @@ The
utility reads files sequentially, writing them to the standard output.
The
.Ar file
operands are processed in command line order.
A single dash represents the standard input.
operands are processed in command-line order.
If
.Ar file
is a single dash
.Pq Sq \&-
or absent,
.Nm
reads from the standard input.
.Pp
The options are as follows:
.Bl -tag -width indent
@ -94,29 +99,94 @@ characters (with the high bit set) are printed as
.Sh DIAGNOSTICS
The
.Nm
utility exits 0 on success, and >0 if an error occurs.
.Sh BUGS
Because of the shell language mechanism used to perform output
redirection, the command
.Dq Li cat file1 file2 > file1
will cause the original data in file1 to be destroyed!
utility exits 0 on success or >0 if an error occurred.
.Sh EXAMPLES
The command:
.Bd -literal -offset indent
.Ic cat file1
.Ed
.Pp
will print the contents of
.Ar file1
to the standard output.
.Pp
The command:
.Bd -literal -offset indent
.Ic cat file1 file2 > file3
.Ed
.Pp
will sequentially print the contents of
.Ar file1
and
.Ar file2
to the file
.Ar file3 ,
truncating
.Ar file3
if it already exists.
See the manual page for your shell (i.e.,
.Xr sh 1 )
for more information on redirection.
.Pp
The command:
.Bd -literal -offset indent
.Ic cat file1 - file2 - file3
.Ed
.Pp
will print the contents of
.Ar file1 ,
print data it receives from the standard input until it receives an
.Dv EOF
.Pq Sq ^D
character, print the contents of
.Ar file2 ,
read and output contents of the standard input again, then finally output
the contents of
.Ar file3 .
Note that if the standard input referred to a file, the second dash
on the command-line would have no effect, since the entire contents of the file
would have already been read and printed by
.Nm
when it encountered the first
.Ql \&-
operand.
.Sh SEE ALSO
.Xr head 1 ,
.Xr more 1 ,
.Xr pr 1 ,
.Xr sh 1 ,
.Xr tail 1 ,
.Xr vis 1
.Xr vis 1 ,
.Xr setbuf 3
.Rs
.%A Rob Pike
.%T "UNIX Style, or cat -v Considered Harmful"
.%J "USENIX Summer Conference Proceedings"
.%D 1983
.Re
.Sh STANDARDS
The
.Nm
utility is compliant with the
.St -p1003.2-92
specification.
.Pp
The flags
.Op Fl benstv
are extensions to the specification.
.Sh HISTORY
A
.Nm
command appeared in Version 1 AT&T UNIX.
utility appeared in
.At v1 .
.An Dennis Ritchie
designed and wrote the first man page.
It appears to have been
.Xr cat 1 .
.Sh BUGS
Because of the shell language mechanism used to perform output
redirection, the command
.Ic cat file1 file2 > file1
will cause the original data in
.Ar file1
to be destroyed!

View File

@ -96,7 +96,7 @@ main(argc, argv)
tflag = vflag = 1; /* -t implies -v */
break;
case 'u':
setbuf(stdout, (char *)NULL);
setbuf(stdout, NULL);
break;
case 'v':
vflag = 1;
@ -249,7 +249,7 @@ raw_cat(rfd)
err(1, "%s", filename);
bsize = MAX(sbuf.st_blksize, 1024);
if ((buf = malloc(bsize)) == NULL)
err(1, NULL);
err(1, "buffer");
}
while ((nr = read(rfd, buf, bsize)) > 0)
for (off = 0; nr; nr -= nw, off += nw)