C - Proper way to close files when using both open() and fdopen()

前端 未结 2 2105
渐次进展
渐次进展 2020-12-10 06:37

So I\'m building a Unix minishell in C, and am implementing input, output, and err redirection, and have come across a problem with files. I open my files in a loop where I

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 06:59

    The standard says:

    The fclose() function shall perform the equivalent of a close() on the file descriptor that is associated with the stream pointed to by stream.

    So calling fclose is enough; it will also close the descriptor.

提交回复
热议问题