-
Notifications
You must be signed in to change notification settings - Fork 96
Use Windows-specific renaming function #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Windows-specific renaming function #90
Conversation
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.
library/psa_its_file.c
Outdated
@@ -209,7 +213,12 @@ psa_status_t psa_its_set( psa_storage_uid_t uid, | |||
} | |||
if( status == PSA_SUCCESS ) | |||
{ | |||
#if defined(_WIN32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid non-structural use of the preprocessor, with #ifdef
around things that aren't a standalone C block. Here, I think the best solution would be to define a function-like macro rename_replace_existing( oldpath, newpath )
with a platform-dependent definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a little documentation improvement please.
library/psa_its_file.c
Outdated
@@ -58,6 +62,13 @@ | |||
#define PSA_ITS_MAGIC_STRING "PSA\0ITS\0" | |||
#define PSA_ITS_MAGIC_LENGTH 8 | |||
|
|||
#if defined(_WIN32) | |||
#define rename_replace_existing( oldpath, newpath ) \ | |||
(!MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style:
(!MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING )) | |
( ! MoveFileExA( oldpath, newpath, MOVEFILE_REPLACE_EXISTING ) ) |
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.