aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-10-21 16:53:41 +0200
committerWerner Koch <wk@gnupg.org>2020-10-21 16:56:46 +0200
commit9a0197b6fe412cfc66b0cece521267180e454416 (patch)
tree0fb574e6613f356d563bd91eadd4fbdb2286ab30
parent18e5dd7b03ced51611c9ba1345cf498a0aaf14a6 (diff)
downloadgnupg-9a0197b6fe412cfc66b0cece521267180e454416.tar.gz
w32: Make gnupg_remove and gnupg_rename_file Unicode aware
* common/sysutils.c (w32_rename): New. (gnupg_rename_file) [W32]: Support Unicode. (gnupg_remove) [W32]: Support Unicode. Drop Windows-CE support. -- GnuPG-bug-id: 5098
-rw-r--r--common/sysutils.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index f8c3a5857..9926c0e52 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -668,7 +668,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;
@@ -677,7 +677,7 @@ gnupg_remove (const char *fname)
rc = 0;
else
{
- rc = DeleteFile (wfname);
+ rc = DeleteFileW (wfname);
xfree (wfname);
}
if (!rc)
@@ -689,6 +689,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
@@ -708,7 +738,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)
{