Skip to content

Commit b467934

Browse files
committed
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.
1 parent c70a3c7 commit b467934

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/psa_its_file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#define mbedtls_snprintf snprintf
3434
#endif
3535

36+
#if defined(_WIN32)
37+
#include <windows.h>
38+
#endif
39+
3640
#include "psa_crypto_its.h"
3741

3842
#include <limits.h>
@@ -209,7 +213,12 @@ psa_status_t psa_its_set( psa_storage_uid_t uid,
209213
}
210214
if( status == PSA_SUCCESS )
211215
{
216+
#if defined(_WIN32)
217+
if( MoveFileExA( PSA_ITS_STORAGE_TEMP, filename,
218+
MOVEFILE_REPLACE_EXISTING ) == 0 )
219+
#else
212220
if( rename( PSA_ITS_STORAGE_TEMP, filename ) != 0 )
221+
#endif
213222
status = PSA_ERROR_STORAGE_FAILURE;
214223
}
215224
remove( PSA_ITS_STORAGE_TEMP );

0 commit comments

Comments
 (0)