如何将文件指针 (FILE* fp) 转换为文件描述符 (int fd)? [英] How can I convert a file pointer ( FILE* fp ) to a file descriptor (int fd)?
本文介绍了如何将文件指针 (FILE* fp) 转换为文件描述符 (int fd)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 FILE *
,通过调用 fopen()
返回.我需要从中获取文件描述符,以在其上进行诸如 fsync(fd)
之类的调用.从文件指针获取文件描述符的函数是什么?
I have a FILE *
, returned by a call to fopen()
. I need to get a file descriptor from it, to make calls like fsync(fd)
on it. What's the function to get a file descriptor from a file pointer?
推荐答案
正确的函数是int fileno(FILE *stream)
.可以在
中找到,是POSIX标准但不是标准C.
The proper function is int fileno(FILE *stream)
. It can be found in <stdio.h>
, and is a POSIX standard but not standard C.
这篇关于如何将文件指针 (FILE* fp) 转换为文件描述符 (int fd)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文