C语言文件指针和文件描述符

来源:互联网 发布:电视直播软件下线了? 编辑:程序博客网 时间:2024/05/18 03:09

#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,

FILE *fopen(const char *path, const char *mode);
fp = fopen(.....);
(1)  fd = fileno(fp);
(2) fd = fp->_file.
0 0
原创粉丝点击