Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/dirinfo.c b/src/dirinfo.c
- index d4811990..d3abead1 100644
- --- a/src/dirinfo.c
- +++ b/src/dirinfo.c
- @@ -260,7 +260,7 @@ get_gpgconf_item (int what)
- char *pgmname;
- pgmname = dirinfo.disable_gpgconf? NULL : _gpgme_get_gpgconf_path ();
- - if (pgmname && access (pgmname, F_OK))
- + if (pgmname && win_access (pgmname, F_OK))
- {
- _gpgme_debug (DEBUG_INIT, -1, NULL, NULL, NULL,
- "gpgme-dinfo: gpgconf='%s' [not installed]\n", pgmname);
- diff --git a/src/w32-io.c b/src/w32-io.c
- index 919ca6fd..a7535433 100644
- --- a/src/w32-io.c
- +++ b/src/w32-io.c
- @@ -1476,8 +1476,13 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
- free (tmp_name);
- return TRACE_SYSRES (-1);
- }
- - if (!CreateProcessA (spawnhelper,
- - arg_string,
- +
- + wchar_t *Utf8ToUtf16(const char *utf8);
- +
- + wchar_t *sh = Utf8ToUtf16(spawnhelper);
- + wchar_t *a = Utf8ToUtf16(arg_string);
- + if (!CreateProcessW (sh,
- + a,
- &sec_attr, /* process security attributes */
- &sec_attr, /* thread security attributes */
- FALSE, /* inherit handles */
- @@ -1490,6 +1495,8 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
- int lasterr = (int)GetLastError ();
- TRACE_LOG ("CreateProcess failed: ec=%d", lasterr);
- free (arg_string);
- + free (sh);
- + free (a);
- close (tmp_fd);
- DeleteFileA (tmp_name);
- free (tmp_name);
- @@ -1498,6 +1505,8 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
- gpg_err_set_errno (EIO);
- return TRACE_SYSRES (-1);
- }
- + free (sh);
- + free (a);
- if (flags & IOSPAWN_FLAG_ALLOW_SET_FG)
- _gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId);
- diff --git a/src/w32-util.c b/src/w32-util.c
- index 9802d9cc..eff7eeb0 100644
- --- a/src/w32-util.c
- +++ b/src/w32-util.c
- @@ -386,6 +386,107 @@ _gpgme_get_inst_dir (void)
- }
- +wchar_t *Utf8ToUtf16(const char *utf8)
- +{
- + size_t len = strlen(utf8);
- +
- + // "Code page" value used with MultiByteToWideChar() for UTF-8 conversion
- + const UINT codePageUtf8 = CP_UTF8;
- +
- + // Safely fails if an invalid UTF-8 character is encountered
- + const DWORD flags = MB_ERR_INVALID_CHARS;
- +
- + // Get the length, in WCHARs, of the resulting UTF-16 string
- + const int utf16Length = MultiByteToWideChar(
- + codePageUtf8, // source string is in UTF-8
- + flags, // conversion flags
- + utf8, // source UTF-8 string
- + len, // length of source UTF-8 string, in chars
- + 0, // unused - no conversion done in this step
- + 0); // request size of destination buffer, in WCHARs
- + if (utf16Length == 0)
- + {
- + // Conversion error
- + return 0;
- + }
- +
- + wchar_t *utf16 = (wchar_t*)malloc((utf16Length + 1) * sizeof(wchar_t));
- + memset(utf16, 0, (utf16Length + 1) * sizeof(wchar_t));
- +
- + // Do the conversion from UTF-8 to UTF-16
- + int result = MultiByteToWideChar(
- + codePageUtf8, // source string is in UTF-8
- + flags, // conversion flags
- + utf8, // source UTF-8 string
- + len, // length of source UTF-8 string, in chars
- + utf16, // pointer to destination buffer
- + utf16Length); // size of destination buffer, in WCHARs
- + if (result == 0)
- + {
- + // Conversion error
- + return 0;
- + }
- +
- + return utf16;
- +}
- +
- +char *Utf16ToUtf8(const wchar_t *utf16)
- +{
- + size_t len = wcslen(utf16);
- +
- + // "Code page" value used with WideCharToMultiByte() for UTF-8 conversion
- + const UINT codePageUtf8 = CP_UTF8;
- +
- + // Safely fails if an invalid UTF-16 character is encountered
- + const DWORD flags = WC_ERR_INVALID_CHARS;
- +
- + // Get the length, in chars, of the resulting UTF-8 string
- + const int utf8Length = WideCharToMultiByte(
- + codePageUtf8, // convert to UTF-8
- + flags, // conversion flags
- + utf16, // source UTF-16 string
- + len, // length of source UTF-16 string, in WCHARs
- + 0, // unused - no conversion required in this step
- + 0, // request size of destination buffer, in chars
- + 0, 0); // unused
- + if (utf8Length == 0)
- + {
- + // Conversion error
- + return 0;
- + }
- +
- + char *utf8 = (char*)malloc(utf8Length + 1);
- + utf8[utf8Length] = 0;
- +
- + // Do the conversion from UTF-16 to UTF-8
- + int result = WideCharToMultiByte(
- + codePageUtf8, // convert to UTF-8
- + flags, // conversion flags
- + utf16, // source UTF-16 string
- + len, // length of source UTF-16 string, in WCHARs
- + utf8, // pointer to destination buffer
- + utf8Length, // size of destination buffer, in chars
- + 0, 0); // unused
- + if (result == 0)
- + {
- + // Conversion error
- + return 0;
- + }
- + return utf8;
- +}
- +
- +int win_access(
- + const char *path,
- + int mode
- +)
- +{
- + wchar_t *u16 = Utf8ToUtf16(path);
- +
- + int r = _waccess(u16, F_OK);
- + free(u16);
- + return r;
- +}
- +
- static char *
- find_program_in_dir (const char *dir, const char *name)
- {
- @@ -395,7 +496,7 @@ find_program_in_dir (const char *dir, const char *name)
- if (!result)
- return NULL;
- - if (access (result, F_OK))
- + if (win_access (result, F_OK))
- {
- free (result);
- return NULL;
- @@ -419,7 +520,7 @@ find_program_at_standard_place (const char *name)
- if (SHGetSpecialFolderPathA (NULL, path, CSIDL_PROGRAM_FILES, 0))
- {
- result = _gpgme_strconcat (path, "\\", name, NULL);
- - if (result && access (result, F_OK))
- + if (result && win_access (result, F_OK))
- {
- free (result);
- result = NULL;
- @@ -429,7 +530,7 @@ find_program_at_standard_place (const char *name)
- && SHGetSpecialFolderPathA (NULL, path, CSIDL_PROGRAM_FILESX86, 0))
- {
- result = _gpgme_strconcat (path, "\\", name, NULL);
- - if (result && access (result, F_OK))
- + if (result && win_access (result, F_OK))
- {
- free (result);
- result = NULL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement