[META] In a future commit in this patchset, it will be used by more than just validation, and it needs to align with fopen anyway.
This is a partial backport of core#25487
https://github.com/bitcoin/bitcoin/pull/25487/commits/b3267258b052557fc136b9a4dcb754afb9219470
Depends on D15719