static char *sccsid
= "@(#)cat.c 4.9 (Berkeley) %G%";
/* #define OPTSIZE BUFSIZ /* define this only if not 4.2 BSD or beyond */
int bflg
, eflg
, nflg
, sflg
, tflg
, uflg
, vflg
;
int spaced
, col
, lno
, inline, ibsize
, obsize
;
for( ; argc
>1 && argv
[1][0]=='-'; argc
--,argv
++) {
setbuf(stdout
, (char *)NULL
);
if (fstat(fileno(stdout
), &statb
) == 0) {
if (statb
.st_mode
!=S_IFCHR
&& statb
.st_mode
!=S_IFBLK
) {
obsize
= statb
.st_blksize
;
if (fflg
|| (*++argv
)[0]=='-' && (*argv
)[1]=='\0')
if ((fi
= fopen(*argv
, "r")) == NULL
) {
if (fstat(fileno(fi
), &statb
) == 0) {
if ((statb
.st_mode
& S_IFMT
) == S_IFREG
&&
statb
.st_dev
==dev
&& statb
.st_ino
==ino
) {
fprintf(stderr
, "cat: input %s is output\n",
ibsize
= statb
.st_blksize
;
while ((c
= getc(fi
)) != EOF
)
retval
|= fastcat(fileno(fi
)); /* no flags specified */
fprintf(stderr
, "cat: output write error\n");
if (nflg
&& bflg
==0 && inline == 0)
if (tflg
==0 && c
== '\t')
register int buffsize
, n
, nwritten
, offset
;
buffsize
= obsize
; /* common case, use output blksize */
if ((buff
= malloc(buffsize
)) == NULL
) {
perror("cat: no memory");
* Note that on some systems (V7), very large writes to a pipe
* return less than the requested size of the write.
* In this case, multiple writes are required.
while ((n
= read(fd
, buff
, buffsize
)) > 0) {
nwritten
= write(fileno(stdout
), &buff
[offset
], n
);
perror("cat: write error");
} while ((n
-= nwritten
) > 0);
perror("cat: read error");