summaryrefslogtreecommitdiff
path: root/src/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-08-21 21:11:21 +0200
committerWerner Koch <wk@gnupg.org>2020-08-21 21:11:21 +0200
commita68c1975bda47b0698b48761a62e95b371095e9a (patch)
treebc5220f82e0da76eaa44e3601773e04c4e470bac /src/sysutils.c
parent87a6b28c0f3b6c5b38e0f8a8533df39d3f0c0f03 (diff)
downloadlibgpg-error-a68c1975bda47b0698b48761a62e95b371095e9a.tar.gz
core,w32: Add UTF-8 support to gpgrt_fopen, gpgrt_mkdir and gpgrt_chdir.
* src/protos.h: New. * src/Makefile.am (libgpg_error_la_SOURCES): Add file. * src/gpgrt-int.h: Include protos.h. * src/sysutils.c (_gpgrt_mkdir) [W32]: Make UTF-8 aware. (_gpgrt_chdir) [W32]: Ditto. * src/w32-gettext.c: Include protos.h. (utf8_to_wchar): Allow for strings. (_gpgrt_utf8_to_wchar): New. (_gpgrt_free_wchar): New. * src/estream.c (map_w32_to_errno): Add more error codes. (_gpgrt_w32_set_errno): New. (any8bitchar) [W32]: New helper. (func_file_create) [W32]: Convert file name and use _wopen. -- GnuPG-bug-id: 4083 Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/sysutils.c')
-rw-r--r--src/sysutils.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/sysutils.c b/src/sysutils.c
index bc446fb..eb5249a 100644
--- a/src/sysutils.c
+++ b/src/sysutils.c
@@ -269,29 +269,34 @@ modestr_to_mode (const char *modestr)
* write allowed, execution allowed with the first group for the user,
* the second for the group and the third for all others. If the
* string is shorter than above the missing mode characters are meant
- * to be not set. */
+ * to be not set.
+ *
+ * Note that in addition to returning an gpg-error error code ERRNO is
+ * also set by this function.
+ */
gpg_err_code_t
_gpgrt_mkdir (const char *name, const char *modestr)
{
-#ifdef HAVE_W32CE_SYSTEM
+#ifdef HAVE_W32_SYSTEM
wchar_t *wname;
+ gpg_err_code_t ec;
(void)modestr;
- wname = utf8_to_wchar (name);
+ /* Note: Fixme: We should set appropriate permissions. */
+ wname = _gpgrt_utf8_to_wchar (name);
if (!wname)
return _gpg_err_code_from_syserror ();
if (!CreateDirectoryW (wname, NULL))
{
- xfree (wname);
- return _gpg_err_code_from_syserror ();
+ _gpgrt_w32_set_errno (-1);
+ ec = _gpg_err_code_from_syserror ();
}
- xfree (wname);
- return 0;
+ else
+ ec = 0;
+ _gpgrt_free_wchar (wname);
+ return ec;
#elif MKDIR_TAKES_ONE_ARG
(void)modestr;
- /* Note: In the case of W32 we better use CreateDirectory and try to
- set appropriate permissions. However using mkdir is easier
- because this sets ERRNO. */
if (mkdir (name))
return _gpg_err_code_from_syserror ();
return 0;
@@ -304,13 +309,34 @@ _gpgrt_mkdir (const char *name, const char *modestr)
/* A simple wrapper around chdir. NAME is expected to be utf8
- * encoded. */
+ * encoded.
+ * Note that in addition to returning an gpg-error error code ERRNO is
+ * also set by this function. */
gpg_err_code_t
_gpgrt_chdir (const char *name)
{
+#ifdef HAVE_W32_SYSTEM
+ wchar_t *wname;
+ gpg_err_code_t ec;
+
+ wname = _gpgrt_utf8_to_wchar (name);
+ if (!wname)
+ return _gpg_err_code_from_syserror ();
+ if (!SetCurrentDirectoryW (wname))
+ {
+ _gpgrt_w32_set_errno (-1);
+ ec = _gpg_err_code_from_syserror ();
+ }
+ else
+ ec = 0;
+ _gpgrt_free_wchar (wname);
+ return ec;
+
+#else /*!HAVE_W32_SYSTEM*/
if (chdir (name))
return _gpg_err_code_from_syserror ();
return 0;
+#endif /*!HAVE_W32_SYSTEM*/
}
@@ -322,6 +348,7 @@ _gpgrt_getcwd (void)
char *buffer;
size_t size = 100;
+ /* FIXME: We need to support utf8 */
for (;;)
{
buffer = xtrymalloc (size+1);
@@ -389,6 +416,7 @@ _gpgrt_getusername (void)
char tmp[1];
DWORD size = 1;
+ /* FIXME: We need to support utf8 */
GetUserNameA (tmp, &size);
result = _gpgrt_malloc (size);
if (result && !GetUserNameA (result, &size))