Is there any ordinary reason to use open() instead of fopen()?

前端 未结 7 1341
南旧
南旧 2021-01-05 13:05

I\'m doing a small project in C after quite a long time away from it. These happen to include some file handling. I noticed in various documentation that there are functions

7条回答
  •  心在旅途
    2021-01-05 13:39

    usually, you should favor using the standard library (fopen). However, there are occasions where you will need to use open directly.

    One example that comes to mind is to work around a bug in an older version of solaris which made fopen fail after 256 files were open. This was because they erroniously used an unsigned char for the fd field in their struct FILE implementation instead of an int. But this was a very specific case.

提交回复
热议问题