/*
 * cat: do what you'd expect it to do
 */
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "glob.h"

#define CBFRSIZ	10240
static char bfr[CBFRSIZ];

/* 
 * masscopy() does the work of copying a file from one place to
 * another.
 */
masscopy(in, out)
register in, out;
{
    register size;

    while ((size=read(in, bfr, CBFRSIZ)) > 0)
	write(out, bfr, size);
} /* masscopy */


/*
 * docat() prints a single file
 */
docat(fn)
char *fn;
{
    register cathan;

    if ((cathan=open(fn, O_RDONLY|O_BINARY)) >= 0) {
	masscopy(cathan, fileno(stdout));
	close(cathan);
    }
    else
	fprintf(stderr, "cat: can't open %s\n",fn);
} /* docat */


/*
 * cat, in the flesh
 */
main(argc, argv)
char **argv;
{
    register i;

    char *fn;

#ifdef MSDOS
    setmode(fileno(stdout), O_BINARY);
#endif
    if (argc > 1) {
	expand_arglist(argc, argv, (void*)0);
	for (i=0; i<myargc; i++)
	    docat(myargv[i]);
    }
    else
	masscopy(fileno(stdin), fileno(stdout));
    exit(0);
} /* main */