As so people know, fopen("/path/to/xxxxx.xxx", "w") empties the file if it exists. I believe that the FreeBSD manual page fopen(3) needs to mention it. The corresponding POSIX manual page fopen(3p) says: w or wb Truncate to zero length or create file for writing. The corresponding Linux manual page fopen(3) says: w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. The following patch is against: https://svnweb.freebsd.org/base/head/lib/libc/stdio/fopen.3?revision=266971&view=co --- fopen.3.orig 2015-08-21 18:48:52 +0800 +++ fopen.3 2015-08-21 18:53:37 +0800 @@ -72,7 +72,7 @@ .It Dq Li w Open for writing. The stream is positioned at the beginning of the file. -Create the file if it does not exist. +Truncate the file to zero length if it exists or create the file if it does not exist. .It Dq Li a Open for writing. The stream is positioned at the end of the file.
A commit references this bug: Author: eadler Date: Sat Dec 23 05:13:39 UTC 2017 New revision: 327099 URL: https://svnweb.freebsd.org/changeset/base/327099 Log: fopen.1: document truncation This documentation truncation similar to POSIX and glibc. PR: 202545 Reported by: intron@intron.ac Changes: head/lib/libc/stdio/fopen.3
A commit references this bug: Author: eadler Date: Mon Jan 15 16:51:05 UTC 2018 New revision: 328006 URL: https://svnweb.freebsd.org/changeset/base/328006 Log: MFC r327099: fopen.1: document truncation This documentation truncation similar to POSIX and glibc. PR: 202545 Changes: _U stable/11/ stable/11/lib/libc/stdio/fopen.3