C语言文件指针和文件描述符
2016-03-08 15:06
381 查看
#include <unistd.h>
int fsync(int fd);
int fdatasync(int fd);
#include <stdio.h>
int fflush(FILE *stream);
注: fsync参数是文件描述符,fflush参数是文件指针
C语言文件指针域文件描述符之间可以相互转换
int fileno(FILE * stream)
FILE * fdopen(int fd, const char * mode)
FILE的结构
struct _iobuf {
char *_ptr; //缓冲区当前指针
int _cnt;
char *_base; //缓冲区基址
int _flag; //文件读写模式
int _file; //文件描述符
int _charbuf; //缓冲区剩余自己个数
int _bufsiz; //缓冲区大小
char *_tmpfname;
};
通过fopen获取的文件指针有两种办法得到fd,
(1) fd = fileno(fp);
(2) fd = fp->_file.
int fsync(int fd);
int fdatasync(int fd);
int fflush(FILE *stream);
注: fsync参数是文件描述符,fflush参数是文件指针
C语言文件指针域文件描述符之间可以相互转换
int fileno(FILE * stream)
FILE * fdopen(int fd, const char * mode)
FILE的结构
struct _iobuf {
char *_ptr; //缓冲区当前指针
int _cnt;
char *_base; //缓冲区基址
int _flag; //文件读写模式
int _file; //文件描述符
int _charbuf; //缓冲区剩余自己个数
int _bufsiz; //缓冲区大小
char *_tmpfname;
};
通过fopen获取的文件指针有两种办法得到fd,
FILE *fopen(const char *path, const char *mode);
fp = fopen(.....);
(1) fd = fileno(fp);
(2) fd = fp->_file.
相关文章推荐
- VS2010下,C++调用python的Runtime error R6034解决方法
- Effiective C++ (一)
- VS2010下,C++调用python的设置
- C++ 模板详解(二)
- C++ 对象模型
- IIR数字滤波器C语言
- JAVA与C++,C与C++的区别
- C++项目之大数四则运算
- C++ String类的简单实现1
- C++ 模板详解(一)
- C语言判断文件夹或者文件是否存在的方法
- codeforces 651C. Watchmen(排列,去重)
- C语言获取本机IP地址
- sqlite3在 C/C++ 程序中应用
- yizhongqishi的线上错题本_c/c++篇
- C++复习基础1
- C++函数重定义、重载、重写
- 字符串的组合
- C语言中的整数(short,int,long)
- C++看人家的代码