//// copyFile2.c// myShell//// Created by baodong on 4/22/15.// Copyright (c) 2015 baodong. All rights reserved.//#include "apue.h"#include "myErr.h"int main(void){
int n;
while ((n = getc(stdin)) != EOF) {
if (putc(n , stdout) == EOF) {
err_sys("输出错误。。。");
}
}
if (ferror(stdin)) {
err_sys("读取出错。。。");
}
return0;
}
无缓冲
//// copyFile.c// myShell//// Created by baodong on 4/22/15.// Copyright (c) 2015 baodong. All rights reserved.//#include <stdio.h>#include "apue.h"#include "myErr.h"#define BUFFERSIZE 10240int main(void){
long n;
char buf[BUFFERSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFERSIZE) )>0) {
if (write(STDOUT_FILENO, buf, n) != n) {
err_sys("写入错误!!!");
}
}
if (n < 0) {
err_sys("读入失败!!!");
}
return0;
}