summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/cat/cat.194
-rw-r--r--bin/cat/cat.c4
2 files changed, 84 insertions, 14 deletions
diff --git a/bin/cat/cat.1 b/bin/cat/cat.1
index a762fb1..740734a 100644
--- a/bin/cat/cat.1
+++ b/bin/cat/cat.1
@@ -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!
diff --git a/bin/cat/cat.c b/bin/cat/cat.c
index f88c125..c2f11dd 100644
--- a/bin/cat/cat.c
+++ b/bin/cat/cat.c
@@ -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)
OpenPOWER on IntegriCloud