1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Replace all calls to access by gnupg_access

* common/sysutils.c (gnupg_access): New.  Replace all calls to access
by this wrapper.
* common/homedir.c (w32_shgetfolderpath): Change to return UTF-8
directory name.
(standard_homedir): Adjust for change.
(w32_commondir, gnupg_cachedir): Ditto.
--

Also use SHGetFolderPathW instead of SHGetFolderPathA on Windows.

This is required to correctly handle non-ascii filenames on Windows.

GnuPG-bug-id: 5098
(cherry picked from commit c94ee1386e)
This commit is contained in:
Werner Koch 2020-10-20 10:43:55 +02:00
parent 25bec16d0b
commit dd5fd4a760
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
28 changed files with 163 additions and 115 deletions

View file

@ -813,7 +813,7 @@ gnupg_chdir (const char *name)
#if GPG_ERROR_VERSION_NUMBER < 0x011c00 /* 1.28 */
return chdir (name);
#else /* Use the improved version from libgpg_error. */
/* Note that gpgrt_chdir also sets ERRNO in addition to returing a
/* Note that gpgrt_chdir also sets ERRNO in addition to returning a
* gpg-error style error code. */
return gpgrt_chdir (name);
#endif
@ -1036,10 +1036,14 @@ gnupg_unsetenv (const char *name)
/* Return the current working directory as a malloced string. Return
NULL and sets ERRNo on error. */
NULL and sets ERRNO on error. */
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. */
char *buffer;
size_t size = 100;
@ -1048,18 +1052,47 @@ gnupg_getcwd (void)
buffer = xtrymalloc (size+1);
if (!buffer)
return NULL;
#ifdef HAVE_W32CE_SYSTEM
# ifdef HAVE_W32CE_SYSTEM
strcpy (buffer, "/"); /* Always "/". */
return buffer;
#else
# else
if (getcwd (buffer, size) == buffer)
return buffer;
xfree (buffer);
if (errno != ERANGE)
return NULL;
size *= 2;
#endif
# endif
}
#else
return gpgrt_getcwd ();
#endif
}
/* A simple wrapper around access. NAME is expected to be utf8
* encoded. This function returns an error code and sets ERRNO. */
gpg_err_code_t
gnupg_access (const char *name, int mode)
{
#if GPGRT_VERSION_NUMBER < 0x012800 /* 1.40 */
# ifdef HAVE_W32_SYSTEM
wchar_t *wfname;
wfname = utf8_to_wchar (fname);
if (!wfname)
ec = gpg_err_code_from_syserror ();
else
{
ec = _waccess (wfname, mode)? gpg_err_code_from_syserror () : 0;
xfree (wfname);
}
# else
return access (name, mode)? gpg_err_code_from_syserror () : 0;
# endif
#else /* gpgrt 1.40 or newer. */
return gpgrt_access (name, mode);
#endif
}