简体   繁体   English

fopen是否创建了文件描述符?

[英]Does fopen create a file descriptor?

Looking at the man page for fopen I cannot get a definite answer to this question. 看看fopen的手册页我无法得到这个问题的明确答案。

FILE *fopen(const char *path, const char *mode);

I understand that fopen returns a file pointer to a stream but is a file descriptor created as a byproduct? 我知道fopen返回一个指向流的文件指针,但是作为副产品创建的文件描述符? I am trying to make sure that I include the flag FD_CLOEXEC on every instance a file descriptor is created. 我试图确保在每个创建文件描述符的实例上都包含标志FD_CLOEXEC If a file descriptor is in fact created from fopen what is the best way to use fnctl() when there is no "fd" to use as input. 如果文件描述符实际上是从fopen创建的,那么当没有“fd”用作输入时,使用fnctl()的最佳方法是什么。

Thanks. 谢谢。

On Unix (which I assume you're using because you're mentioning fcntl ) it does open a file descriptor, as fopen(3) eventually calls open(2). 在Unix上(我假设你正在使用,因为你提到fcntl )它确实打开了一个文件描述符,因为fopen(3)最终调用open(2). You can get that file descriptor via fileno(3) . 您可以通过fileno(3)获取该文件描述符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM