mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-20 14:37:08 +01:00
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 <wk@gnupg.org>
This commit is contained in:
parent
0ca0a30bd6
commit
9188a3c6b7
@ -1100,9 +1100,33 @@ char *
|
|||||||
gnupg_getcwd (void)
|
gnupg_getcwd (void)
|
||||||
{
|
{
|
||||||
#if GPGRT_VERSION_NUMBER < 0x012800 /* 1.40 */
|
#if GPGRT_VERSION_NUMBER < 0x012800 /* 1.40 */
|
||||||
/* We use the old code which is okay despite that it does not
|
# ifdef HAVE_W32_SYSTEM
|
||||||
* support Unicode on Windows. For Windows this doesn't matter
|
wchar_t wbuffer[MAX_PATH + sizeof(wchar_t)];
|
||||||
* because we use the latest gpgrt anyway. */
|
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;
|
char *buffer;
|
||||||
size_t size = 100;
|
size_t size = 100;
|
||||||
|
|
||||||
@ -1111,18 +1135,14 @@ gnupg_getcwd (void)
|
|||||||
buffer = xtrymalloc (size+1);
|
buffer = xtrymalloc (size+1);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return NULL;
|
return NULL;
|
||||||
# ifdef HAVE_W32CE_SYSTEM
|
|
||||||
strcpy (buffer, "/"); /* Always "/". */
|
|
||||||
return buffer;
|
|
||||||
# else
|
|
||||||
if (getcwd (buffer, size) == buffer)
|
if (getcwd (buffer, size) == buffer)
|
||||||
return buffer;
|
return buffer;
|
||||||
xfree (buffer);
|
xfree (buffer);
|
||||||
if (errno != ERANGE)
|
if (errno != ERANGE)
|
||||||
return NULL;
|
return NULL;
|
||||||
size *= 2;
|
size *= 2;
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
# endif /*Unix*/
|
||||||
#else
|
#else
|
||||||
return gpgrt_getcwd ();
|
return gpgrt_getcwd ();
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user