aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-11-10 09:04:16 +0000
committerWerner Koch <[email protected]>2020-11-10 09:11:11 +0000
commit9188a3c6b7eb871f711a0979620ca72f99522d53 (patch)
treed16768df5d78bc8c0dad9f6af2d1a850ef26f735
parentPrepare NEWS for the next release. (diff)
downloadgnupg-9188a3c6b7eb871f711a0979620ca72f99522d53.tar.gz
gnupg-9188a3c6b7eb871f711a0979620ca72f99522d53.zip
w32: Support utf8 for getcwd even if build with gpgrt < 1.40.
* common/sysutils.c (gnupg_getcwd) [W32]: Use Unicode version. -- gpgrt 1.40 has not yet been released, so to make getcwd work properly on Windows we need to have the code here as well. GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--common/sysutils.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index 05fadb3d7..df62aa254 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -1100,9 +1100,33 @@ char *
gnupg_getcwd (void)
{
#if GPGRT_VERSION_NUMBER < 0x012800 /* 1.40 */
- /* We use the old code which is okay despite that it does not
- * support Unicode on Windows. For Windows this doesn't matter
- * because we use the latest gpgrt anyway. */
+# ifdef HAVE_W32_SYSTEM
+ wchar_t wbuffer[MAX_PATH + sizeof(wchar_t)];
+ DWORD wlen;
+ char *buf, *p;
+
+ wlen = GetCurrentDirectoryW (MAX_PATH, wbuffer);
+ if (!wlen)
+ {
+ gpg_err_set_errno (EINVAL);
+ return NULL;
+
+ }
+ else if (wlen > MAX_PATH)
+ {
+ gpg_err_set_errno (ENAMETOOLONG);
+ return NULL;
+ }
+ buf = wchar_to_utf8 (wbuffer);
+ if (buf)
+ {
+ for (p=buf; *p; p++)
+ if (*p == '\\')
+ *p = '/';
+ }
+ return buf;
+
+# else /*Unix*/
char *buffer;
size_t size = 100;
@@ -1111,18 +1135,14 @@ gnupg_getcwd (void)
buffer = xtrymalloc (size+1);
if (!buffer)
return NULL;
-# ifdef HAVE_W32CE_SYSTEM
- strcpy (buffer, "/"); /* Always "/". */
- return buffer;
-# else
if (getcwd (buffer, size) == buffer)
return buffer;
xfree (buffer);
if (errno != ERANGE)
return NULL;
size *= 2;
-# endif
}
+# endif /*Unix*/
#else
return gpgrt_getcwd ();
#endif