From: http://blog.163.com/xychenbaihu@yeah/blog/static/1322296552011625112831213/
文件指针---->文件描述符: // fp ----> fd
FILE *fp = NULL;
fp = fopen("/home/billchen/test.txt","r"); //得到文件描述符
if (fp == NULL)
{
perror("open file error:");
exit(1);
}
else
{
//成功
}
将fp转换成文件描述符:
int fd ;
fd = fileno(fp);
文件描述符---->文件指针: // fd---->fp
int fd;
fd = open("/home/billchen/test.txt",O_CREAT|O_RDWR,0666);
if ( fd == -1 )
{
perror("open file error:");
exit(1);
}
else
{
//成功
}
将fd转换成文件指针:
FILE *fp = NULL;
fp = fdopen(fd);
=============================================================================================
总结:
int fd;
FILE *fp;
fd = fileno(fp);