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

前端 未结 2 2107
渐次进展
渐次进展 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:58

    FILE is a buffering object from standard C library. When you do fclose (standard C function) it will eventually call close (Unix system function) but only after making sure C library buffers are flushed. So, I would say, if you use fopen andfwrite then you should use fclose, and not just close, otherwise you risk loosing some data.

提交回复
热议问题