If you happen to write to a file on a Linux/Unix/Posix system, then you might be tempted to open the file with O_WRONLY | O_CREAT. I’m here to warn you that you probably want O_WRONLY | O_CREAT | O_TRUNC. Noticing this mistake took me an embarrassing amount of time to track down.
Share this post
Writing to a Posix File
Share this post
If you happen to write to a file on a Linux/Unix/Posix system, then you might be tempted to open the file with O_WRONLY | O_CREAT. I’m here to warn you that you probably want O_WRONLY | O_CREAT | O_TRUNC. Noticing this mistake took me an embarrassing amount of time to track down.