File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 33
33
#define mbedtls_snprintf snprintf
34
34
#endif
35
35
36
+ #if defined(_WIN32 )
37
+ #include <windows.h>
38
+ #endif
39
+
36
40
#include "psa_crypto_its.h"
37
41
38
42
#include <limits.h>
58
62
#define PSA_ITS_MAGIC_STRING "PSA\0ITS\0"
59
63
#define PSA_ITS_MAGIC_LENGTH 8
60
64
65
+ /* As rename fails on Windows if the new filepath already exists,
66
+ * use MoveFileExA with the MOVEFILE_REPLACE_EXISTING flag instead.
67
+ * Returns 0 on success, nonzero on failure. */
68
+ #if defined(_WIN32 )
69
+ #define rename_replace_existing ( oldpath , newpath ) \
70
+ ( ! MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ) )
71
+ #else
72
+ #define rename_replace_existing ( oldpath , newpath ) rename( oldpath, newpath )
73
+ #endif
74
+
61
75
typedef struct
62
76
{
63
77
uint8_t magic [PSA_ITS_MAGIC_LENGTH ];
@@ -209,7 +223,7 @@ psa_status_t psa_its_set( psa_storage_uid_t uid,
209
223
}
210
224
if ( status == PSA_SUCCESS )
211
225
{
212
- if ( rename ( PSA_ITS_STORAGE_TEMP , filename ) != 0 )
226
+ if ( rename_replace_existing ( PSA_ITS_STORAGE_TEMP , filename ) != 0 )
213
227
status = PSA_ERROR_STORAGE_FAILURE ;
214
228
}
215
229
remove ( PSA_ITS_STORAGE_TEMP );
You can’t perform that action at this time.
0 commit comments