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.