Skip to content

Commit fdda7de

Browse files
committed
Use function-like macro for Windows renaming
1 parent b467934 commit fdda7de

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

library/psa_its_file.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
#define PSA_ITS_MAGIC_STRING "PSA\0ITS\0"
6363
#define PSA_ITS_MAGIC_LENGTH 8
6464

65+
#if defined(_WIN32)
66+
#define rename_replace_existing( oldpath, newpath ) \
67+
(!MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ))
68+
#else
69+
#define rename_replace_existing( oldpath, newpath ) rename( oldpath, newpath )
70+
#endif
71+
6572
typedef struct
6673
{
6774
uint8_t magic[PSA_ITS_MAGIC_LENGTH];
@@ -213,12 +220,7 @@ psa_status_t psa_its_set( psa_storage_uid_t uid,
213220
}
214221
if( status == PSA_SUCCESS )
215222
{
216-
#if defined(_WIN32)
217-
if( MoveFileExA( PSA_ITS_STORAGE_TEMP, filename,
218-
MOVEFILE_REPLACE_EXISTING ) == 0 )
219-
#else
220-
if( rename( PSA_ITS_STORAGE_TEMP, filename ) != 0 )
221-
#endif
223+
if( rename_replace_existing( PSA_ITS_STORAGE_TEMP, filename ) != 0 )
222224
status = PSA_ERROR_STORAGE_FAILURE;
223225
}
224226
remove( PSA_ITS_STORAGE_TEMP );

0 commit comments

Comments
 (0)