Add umask and rename compatibility wrappers for Windows

umask() doesn't exist on Windows and is thus a no-op.

rename() only works if the destination doesn't already exist,
so we must unlink before renaming.
This commit is contained in:
Cyril Cleaud
2014-06-26 22:59:17 -07:00
committed by Andrew Ayer
parent dcea03f0d7
commit df2b472cd9
5 changed files with 32 additions and 6 deletions

View File

@@ -134,9 +134,9 @@ bool Key_file::load_from_file (const char* key_file_name)
bool Key_file::store_to_file (const char* key_file_name) const
{
mode_t old_umask = umask(0077); // make sure key file is protected (TODO: Windows compat)
mode_t old_umask = util_umask(0077); // make sure key file is protected
std::ofstream key_file_out(key_file_name, std::fstream::binary);
umask(old_umask);
util_umask(old_umask);
if (!key_file_out) {
return false;
}