Is there a Windows equivalent to fdopen for HANDLEs?

前端 未结 2 1808
滥情空心
滥情空心 2020-11-27 18:01

In Unix, if you have a file descriptor (e.g. from a socket, pipe, or inherited from your parent process), you can open a buffered I/O FILE* stream on it with fd

2条回答
  •  悲哀的现实
    2020-11-27 18:44

    Here is a more elegant way of doing this instead of CreateFile: specify "N" in fopen(). It's a Microsoft-specific extension to fopen, but since this code is platform-specific anyway, it's ok. When called with "N", fopen adds _O_NOINHERIT flag when calling _open internally.

    Based on this: Windows C Run-Time _close(fd) not closing file

提交回复
热议问题