Linux C:如何从文件描述符更改为 FILE 结构,反之亦然?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4210966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C : how can I change from file descriptor to FILE struct and vice versa?
提问by trrrrrrm
Is there any way to change an int
file descriptor to a FILE
struct pointer or/and change FILE*
to a file descriptor in C?
有没有办法将int
文件描述符更改为FILE
结构指针或/和更改FILE*
为 C 中的文件描述符?
采纳答案by Kamal
The function fdopen()
returns a new (FILE *) associated with an open file descriptor.
该函数fdopen()
返回一个与打开的文件描述符相关联的新 (FILE *)。
The function fileno()
returns the file descriptor associated with an open FILE *.
该函数fileno()
返回与打开的 FILE * 关联的文件描述符。