3.3 将标准输入复制到标准输出

mycat/mycat.c

#include "apue.h"
#define	BUFFSIZE	4096
int
main(void)
{
	int		n;
	char	buf[BUFFSIZE];
	while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
		if (write(STDOUT_FILENO, buf, n) != n)
			err_sys("write error");
	if (n < 0)
		err_sys("read error");
	exit(0);
}
posted @ 2014-07-16 23:13  paullam  阅读(147)  评论(0编辑  收藏  举报