summaryrefslogtreecommitdiffstats
path: root/common/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-10-20 14:08:35 +0200
committerWerner Koch <wk@gnupg.org>2020-10-20 14:08:35 +0200
commit4dcef0e17836e8725c31a3b76f2bf7144345c808 (patch)
treee75dc82afa98ea964ee65fde05608a6148214ffe /common/sysutils.c
parentw32: Allow Unicode filenames for dotlock (diff)
downloadgnupg2-4dcef0e17836e8725c31a3b76f2bf7144345c808.tar.xz
gnupg2-4dcef0e17836e8725c31a3b76f2bf7144345c808.zip
Replace most calls to open by a new wrapper.
* common/sysutils.c (any8bitchar) [W32]: New. (gnupg_open): New. Replace most calls to open by this. * common/iobuf.c (any8bitchar) [W32]: New. (direct_open) [W32]: Use CreateFileW if needed. -- This is yet another step for full Unicode support on Windows. GnuPG-bug-id: 5098
Diffstat (limited to 'common/sysutils.c')
-rw-r--r--common/sysutils.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index 6738da108..bfb5d7dd8 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -182,6 +182,18 @@ enable_core_dumps (void)
#endif
}
+#ifdef HAVE_W32_SYSTEM
+static int
+any8bitchar (const char *string)
+{
+ if (string)
+ for ( ; *string; string++)
+ if ((*string & 0x80))
+ return 1;
+ return 0;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
/* Allow the use of special "-&nnn" style file names. */
void
@@ -1066,6 +1078,30 @@ gnupg_access (const char *name, int mode)
#endif
}
+/* A wrapper around open to handle Unicode file names under Windows. */
+int
+gnupg_open (const char *name, int flags, unsigned int mode)
+{
+#ifdef HAVE_W32_SYSTEM
+ if (any8bitchar (name))
+ {
+ wchar_t *wname;
+ int ret;
+
+ wname = utf8_to_wchar (name);
+ if (!wname)
+ return -1;
+ ret = _wopen (wname, flags, mode);
+ xfree (wname);
+ return ret;
+ }
+ else
+ return open (name, flags, mode);
+#else
+ return open (name, flags, mode);
+#endif
+}
+
/* Try to set an envvar. Print only a notice on error. */
#ifndef HAVE_W32_SYSTEM