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

Replace most calls to open by a new wrapper.

* common/sysutils.c (any8bitchar) [W32]: New.
(gnupg_open): New.  Replace most calls to open by this.
* common/iobuf.c (any8bitchar) [W32]: New.
(direct_open) [W32]: Use CreateFileW if needed.
--

This is yet another step for full Unicode support on Windows.

GnuPG-bug-id: 5098
This commit is contained in:
Werner Koch 2020-10-20 14:08:35 +02:00
parent b47c355b18
commit 4dcef0e178
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
8 changed files with 79 additions and 26 deletions

View file

@ -198,6 +198,19 @@ fd_cache_strcmp (const char *a, const char *b)
#endif
}
#ifdef HAVE_W32_SYSTEM
static int
any8bitchar (const char *string)
{
if (string)
for ( ; *string; string++)
if ((*string & 0x80))
return 1;
return 0;
}
#endif /*HAVE_W32_SYSTEM*/
/*
* Invalidate (i.e. close) a cached iobuf
*/
@ -299,21 +312,23 @@ direct_open (const char *fname, const char *mode, int mode700)
sm = FILE_SHARE_READ;
}
#ifdef HAVE_W32CE_SYSTEM
{
wchar_t *wfname = utf8_to_wchar (fname);
if (wfname)
{
hfile = CreateFile (wfname, da, sm, NULL, cd,
FILE_ATTRIBUTE_NORMAL, NULL);
xfree (wfname);
}
else
hfile = INVALID_HANDLE_VALUE;
}
#else
hfile = CreateFile (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL);
#endif
/* We use the Unicode version of the function only if needed to
* avoid an extra conversion step. */
if (any8bitchar (fname))
{
wchar_t *wfname = utf8_to_wchar (fname);
if (wfname)
{
hfile = CreateFileW (wfname, da, sm, NULL, cd,
FILE_ATTRIBUTE_NORMAL, NULL);
xfree (wfname);
}
else
hfile = INVALID_HANDLE_VALUE;
}
else
hfile = CreateFileA (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL);
return hfile;
#else /*!HAVE_W32_SYSTEM*/