#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* spit a file (stdin) into 2meg chunks */
#define twomeg (2*1024*1024)
char rbuf[twomeg];
main(int argc, char *argv[])
{
	int rcount;
	int nreads = 0;
	char f2name[100]; 
	int fd2;
	while ((rcount = read(0,rbuf,twomeg))>0)
	{
		sprintf(f2name,"%s.%d",argv[1],nreads);
		fd2 = creat(f2name,0644);
		if (write(fd2,rbuf,rcount)<rcount)
		{
			perror("write failed");
			exit();
		}
		nreads++;
	}
	if (rcount<0)
		perror("read failed");
}





