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

w32: Support Unicode also for config files etc.

* common/sysutils.c (gnupg_fopen) [W32]: Use _wfopen if needed.   Use
new function in most places where fopen is used.
--

The config files in 2.2 are still read using fopen - we need to change
this to allow Unicode directory names.  There is also one case where
files are written using the old fopen.  The new option parser in 2.3
does not have this problem but at some places fopen is also still used.

GnuPG-bug-id: 5098
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-11-10 12:09:11 +01:00
parent 9188a3c6b7
commit 163e4ff195
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
20 changed files with 76 additions and 25 deletions

View file

@ -1219,6 +1219,55 @@ gnupg_stat (const char *name, struct stat *statbuf)
#endif /*HAVE_STAT*/
/* Wrapper around fopen for the cases where we have not yet switched
* to es_fopen. Note that for convenience the prototype is in util.h */
FILE *
gnupg_fopen (const char *fname, const char *mode)
{
#ifdef HAVE_W32_SYSTEM
if (any8bitchar (fname))
{
wchar_t *wfname;
const wchar_t *wmode;
wchar_t *wmodebuf = NULL;
FILE *ret;
wfname = utf8_to_wchar (fname);
if (!wfname)
return NULL;
if (!strcmp (mode, "r"))
wmode = L"r";
else if (!strcmp (mode, "rb"))
wmode = L"rb";
else if (!strcmp (mode, "w"))
wmode = L"w";
else if (!strcmp (mode, "wb"))
wmode = L"wb";
else
{
wmodebuf = utf8_to_wchar (mode);
if (!wmodebuf)
{
xfree (wfname);
return NULL;
}
wmode = wmodebuf;
}
ret = _wfopen (wfname, wmode);
xfree (wfname);
xfree (wmodebuf);
return ret;
}
else
return fopen (fname, mode);
#else /*Unix*/
return fopen (fname, mode);
#endif /*Unix*/
}
/* A wrapper around open to handle Unicode file names under Windows. */
int
gnupg_open (const char *name, int flags, unsigned int mode)