Use Windows-specific renaming function

On Windows, rename() fails if the new filename already exists.
Use the Windows specific function MoveFileExA with the
MOVEFILE_REPLACE_EXISTING flag set instead to do renames.
This commit is contained in:
Darryl Green 2019-04-10 15:37:06 +01:00
parent c70a3c76bf
commit b467934fb7

View file

@ -33,6 +33,10 @@
#define mbedtls_snprintf snprintf
#endif
#if defined(_WIN32)
#include <windows.h>
#endif
#include "psa_crypto_its.h"
#include <limits.h>
@ -209,7 +213,12 @@ exit:
}
if( status == PSA_SUCCESS )
{
#if defined(_WIN32)
if( MoveFileExA( PSA_ITS_STORAGE_TEMP, filename,
MOVEFILE_REPLACE_EXISTING ) == 0 )
#else
if( rename( PSA_ITS_STORAGE_TEMP, filename ) != 0 )
#endif
status = PSA_ERROR_STORAGE_FAILURE;
}
remove( PSA_ITS_STORAGE_TEMP );