main.c

来自「unix高级编程源代码.<<unix高级编程>>」· C语言 代码 · 共 31 行

C
31
字号
#include	"open.h"
#include	<fcntl.h>

#define	BUFFSIZE	8192

int
main(int argc, char *argv[])
{
	int		n, fd;
	char	buf[BUFFSIZE], line[MAXLINE];

					/* read filename to cat from stdin */
	while (fgets(line, MAXLINE, stdin) != NULL) {
		line[strlen(line) - 1] = 0;	/* replace newline with null */

					/* open the file */
		if ( (fd = csopen(line, O_RDONLY)) < 0)
			continue;	/* csopen() prints error from server */

					/* and cat to stdout */
		while ( (n = read(fd, buf, BUFFSIZE)) > 0)
			if (write(STDOUT_FILENO, buf, n) != n)
				err_sys("write error");
		if (n < 0)
			err_sys("read error");
		close(fd);
	}

	exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?