* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)cat.c 5.9 (Berkeley) %G%";
int bflag
, eflag
, nflag
, sflag
, tflag
, vflag
;
extern int errno
, optind
;
while ((ch
= getopt(argc
, argv
, "benstuv")) != EOF
)
bflag
= nflag
= 1; /* -b implies -n */
eflag
= vflag
= 1; /* -e implies -v */
tflag
= vflag
= 1; /* -t implies -v */
setbuf(stdout
, (char *)NULL
);
"usage: cat [-benstuv] [-] [file ...]\n");
if (bflag
|| eflag
|| nflag
|| sflag
|| tflag
|| vflag
)
else if (!(fp
= fopen(*argv
, "r"))) {
"cat: %s: %s\n", *argv
, strerror(errno
));
register int ch
, gobble
, line
, prev
;
for (prev
= '\n'; (ch
= getc(fp
)) != EOF
; prev
= ch
) {
if (!gobble
&& putchar(ch
) == EOF
)
(void)fprintf(stdout
, "%6d\t", ++line
);
(void)fprintf(stdout
, "%6d\t", ++line
);
if (putchar('^') == EOF
|| putchar('I') == EOF
)
if (putchar('M') == EOF
|| putchar('-') == EOF
)
if (putchar('^') == EOF
||
putchar(ch
== '\177' ? '?' :
(void)fprintf(stderr
, "cat: %s: read error\n", filename
);
(void)fprintf(stderr
, "cat: stdout: write error\n");
else if ((fd
= open(*argv
, O_RDONLY
, 0)) < 0) {
(void)fprintf(stderr
, "cat: %s: %s\n",
register int nr
, nw
, off
;
char *malloc(), *strerror();
if (fstat(fileno(stdout
), &sbuf
)) {
(void)fprintf(stderr
, "cat: %s: %s\n", filename
,
bsize
= MAX(sbuf
.st_blksize
, 1024);
if (!(buf
= malloc((u_int
)bsize
))) {
(void)fprintf(stderr
, "cat: %s: no memory.\n",
while ((nr
= read(fd
, buf
, bsize
)) > 0)
for (off
= 0; off
< nr
;) {
if ((nw
= write(fileno(stdout
), buf
+ off
, nr
)) < 0) {
(void)fprintf(stderr
, "cat: %s: %s\n", filename
,