现在的位置: 首页 > 综合 > 正文

apue(1-2)

2012年03月16日 ⁄ 综合 ⁄ 共 351字 ⁄ 字号 评论关闭

/*
 * DESCRIPTION: read from stdin to stdout;
 * copy any UNIX file context ;
 * e.g: a.out > file.data;
 * e.g: a.out < infile > outfile;
 * DATE:8-23-2006
*/

#include "apue.h"

#define BUFSIZE 4096

int main(void)
{
 int n;
 char buf[BUFSIZE];
 while((n = read(STDIN_FILENO, buf, BUFSIZE)) > 0)
  if(write(STDOUT_FILENO, buf, n) != n)
   err_sys("write error!");
 if(n < 0)
  err_sys("read error!");
 return 0;

抱歉!评论已关闭.