gpt4 book ai didi

c - 如何从文件描述符获取 FILE* 流?

转载 作者:IT王子 更新时间:2023-10-29 00:24:42 25 4
gpt4 key购买 nike

我们可以使用 fileno() 函数从 FILE* 流中获取文件描述符。是否有无需重新打开文件即可从文件描述符获取 FILE* 流的函数?

最佳答案

   FILE *fdopen(int fd, const char *mode);

参见fdopen(3),但它应该与fopen(3)在同一页面上:

The fdopen() function associates a stream with the existing file descriptor, fd. The mode of the stream (one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor. The file position indicator of the new stream is set to that belonging to fd, and the error and end-of-file indicators are cleared. Modes "w" or "w+" do not cause truncation of the file. The file descriptor is not dup’ed, and will be closed when the stream created by fdopen() is closed. The result of applying fdopen() to a shared memory object is undefined.

关于c - 如何从文件描述符获取 FILE* 流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1516766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com