diff --git a/common/sysutils.c b/common/sysutils.c index 842efb975..422a783e5 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -641,7 +641,7 @@ gnupg_allow_set_foregound_window (pid_t pid) int gnupg_remove (const char *fname) { -#ifdef HAVE_W32CE_SYSTEM +#ifdef HAVE_W32_SYSTEM int rc; wchar_t *wfname; @@ -650,7 +650,7 @@ gnupg_remove (const char *fname) rc = 0; else { - rc = DeleteFile (wfname); + rc = DeleteFileW (wfname); xfree (wfname); } if (!rc) @@ -662,6 +662,36 @@ gnupg_remove (const char *fname) } +/* Helper for gnupg_rename_file. */ +#ifdef HAVE_W32_SYSTEM +static int +w32_rename (const char *oldname, const char *newname) +{ + if (any8bitchar (oldname) || any8bitchar (newname)) + { + wchar_t *woldname, *wnewname; + int ret; + + woldname = utf8_to_wchar (oldname); + if (!woldname) + return -1; + wnewname = utf8_to_wchar (newname); + if (!wnewname) + { + xfree (wnewname); + return -1; + } + ret = _wrename (woldname, wnewname); + xfree (wnewname); + xfree (woldname); + return ret; + } + else + return rename (oldname, newname); +} +#endif /*HAVE_W32_SYSTEM*/ + + /* Wrapper for rename(2) to handle Windows peculiarities. If * BLOCK_SIGNALS is not NULL and points to a variable set to true, all * signals will be blocked by calling gnupg_block_all_signals; the @@ -681,7 +711,7 @@ gnupg_rename_file (const char *oldname, const char *newname, int *block_signals) gnupg_remove (newname); again: - if (rename (oldname, newname)) + if (w32_rename (oldname, newname)) { if (GetLastError () == ERROR_SHARING_VIOLATION) {