FILE的缓冲模式

来源:互联网 发布:c语言更改define 编辑:程序博客网 时间:2024/04/29 16:38

0x01 关于这个问题

三种缓冲模式:
无缓冲,如stdout
行缓冲,如stderr
全缓冲

0x02 文件描述符

0,stdin1,stdout2,stderr

0x03 缓冲的设置

缓冲的设置

0x04 代码实现stdout重定向到文件

stdout重定向
函数dup2,用于复制文件句柄
dup2(int oldhandle, int newhandle);

函数fileno,用于转换FILE为文件描述符fd
该代码的思路为:
1,打开一个文件,作为stdout重定向的目标
2,关闭标准输出stdout
3,使用dup2使得stdout指向新打开的这个文件

0 0
原创粉丝点击