diff options
author | Werner Koch <[email protected]> | 2020-10-20 08:43:55 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2020-10-20 10:15:55 +0000 |
commit | c94ee1386e0d5cdac51086c4d5b92de59c09c9b5 (patch) | |
tree | 34089b99da850a449f95ab9dd7e88317194b5f11 /common/sysutils.c | |
parent | gpg,ecc: Fix SOS handling when receiving from agent. (diff) | |
download | gnupg-c94ee1386e0d5cdac51086c4d5b92de59c09c9b5.tar.gz gnupg-c94ee1386e0d5cdac51086c4d5b92de59c09c9b5.zip |
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
Diffstat (limited to 'common/sysutils.c')
-rw-r--r-- | common/sysutils.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/common/sysutils.c b/common/sysutils.c index 140d1d7be..99bc021f5 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -811,7 +811,7 @@ gnupg_mkdir (const char *name, const char *modestr) int gnupg_chdir (const char *name) { - /* Note that gpgrt_chdir also sets ERRNO in addition to returing an + /* Note that gpgrt_chdir also sets ERRNO in addition to returning an * gpg-error style error code. */ return gpgrt_chdir (name); } @@ -1033,30 +1033,37 @@ 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) { - char *buffer; - size_t size = 100; + return gpgrt_getcwd (); +} + + +/* 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.39 */ +# ifdef HAVE_W32_SYSTEM + wchar_t *wfname; - for (;;) + wfname = utf8_to_wchar (fname); + if (!wfname) + ec = gpg_err_code_from_syserror (); + else { - buffer = xtrymalloc (size+1); - if (!buffer) - return NULL; -#ifdef HAVE_W32CE_SYSTEM - strcpy (buffer, "/"); /* Always "/". */ - return buffer; + 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 - if (getcwd (buffer, size) == buffer) - return buffer; - xfree (buffer); - if (errno != ERANGE) - return NULL; - size *= 2; + return gpgrt_access (name, mode); #endif - } } |