freopen内部实现

 1 #include <unistd.h>
 2 #include <stdio.h>
 3 
 4 FILE* Freopen(const char *fileName, const char *type, FILE *stream){
 5   FILE *fileFp = fopen(fileName, type);
 6   int fd1 = fileno(fileFp);
 7   int fd2 = fileno(stream);
 8   if(dup2(fd1, fd2) < 0) return NULL;
 9   else return stream;
10 }

 

posted @ 2014-06-07 10:59  aclove  阅读(366)  评论(0编辑  收藏  举报