Merge pull request #90 from dgreen-arm/fix-its-file-on-windows

Use Windows-specific renaming function
This commit is contained in:
Jaeden Amero 2019-04-15 10:23:19 +01:00 committed by GitHub
commit 125a1e980e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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>
@ -58,6 +62,16 @@
#define PSA_ITS_MAGIC_STRING "PSA\0ITS\0"
#define PSA_ITS_MAGIC_LENGTH 8
/* As rename fails on Windows if the new filepath already exists,
* use MoveFileExA with the MOVEFILE_REPLACE_EXISTING flag instead.
* Returns 0 on success, nonzero on failure. */
#if defined(_WIN32)
#define rename_replace_existing( oldpath, newpath ) \
( ! MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ) )
#else
#define rename_replace_existing( oldpath, newpath ) rename( oldpath, newpath )
#endif
typedef struct
{
uint8_t magic[PSA_ITS_MAGIC_LENGTH];
@ -209,7 +223,7 @@ exit:
}
if( status == PSA_SUCCESS )
{
if( rename( PSA_ITS_STORAGE_TEMP, filename ) != 0 )
if( rename_replace_existing( PSA_ITS_STORAGE_TEMP, filename ) != 0 )
status = PSA_ERROR_STORAGE_FAILURE;
}
remove( PSA_ITS_STORAGE_TEMP );