summaryrefslogtreecommitdiff
path: root/src/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-10-19 15:21:59 +0200
committerWerner Koch <wk@gnupg.org>2020-10-19 15:21:59 +0200
commit4764c5a3a4d704b3b42bafc5eba3996579030703 (patch)
tree44983a7d7b811145c19de90bd01e52c979815a52 /src/sysutils.c
parentdbedf190969de1a796560cfa15fb4ea986bc79dc (diff)
downloadlibgpg-error-4764c5a3a4d704b3b42bafc5eba3996579030703.tar.gz
New public function gpgrt_access.
* src/gpg-error.h.in (gpgrt_access): New. * src/gpg-error.vers. src/gpg-error.def.in: Add new function. * src/sysutils.c (any8bitchar): New. (_gpgrt_access): New. * src/visibility.c (gpgrt_access): New. * src/spawn-w32.c (_gpgrt_spawn_process_detached): Use it. * src/argparse.c (try_versioned_conffile): Use it. * tests/t-stringutils.c (check_access): New simple test. -- This is basically a wrapper to allow handling of utf8 encoded file names on Windows. This also fixes the case for versioned config files in directories with non-ascii characters. The new test needs to be run manually on Windows using a directory with Unicode characters. GnuPG-bug-id: 5098
Diffstat (limited to 'src/sysutils.c')
-rw-r--r--src/sysutils.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/sysutils.c b/src/sysutils.c
index 36daaec..8005a51 100644
--- a/src/sysutils.c
+++ b/src/sysutils.c
@@ -39,6 +39,19 @@
#include "gpgrt-int.h"
+#ifdef HAVE_W32_SYSTEM
+/* Return true if STRING has any 8 bit character. */
+static int
+any8bitchar (const char *string)
+{
+ if (string)
+ for ( ; *string; string++)
+ if ((*string & 0x80))
+ return 1;
+ return 0;
+}
+#endif /*HAVE_W32_SYSTEM*/
+
/* Return true if FD is valid. */
int
@@ -395,6 +408,36 @@ _gpgrt_getcwd (void)
}
+/* Wrapper around access to handle file name encoding under Windows.
+ * Returns 0 if FNAME can be accessed in MODE or an error code. */
+gpg_err_code_t
+_gpgrt_access (const char *fname, int mode)
+{
+ gpg_err_code_t ec;
+
+#ifdef HAVE_W32_SYSTEM
+ if (any8bitchar (fname))
+ {
+ wchar_t *wfname;
+
+ wfname = _gpgrt_utf8_to_wchar (fname);
+ if (!wfname)
+ ec = _gpg_err_code_from_syserror ();
+ else
+ {
+ ec = _waccess (wfname, mode)? _gpg_err_code_from_syserror () : 0;
+ _gpgrt_free_wchar (wfname);
+ }
+ }
+ else
+#endif /*HAVE_W32_SYSTEM*/
+ ec = access (fname, mode)? _gpg_err_code_from_syserror () : 0;
+
+ return ec;
+}
+
+
+
/* Get the standard home directory for user NAME. If NAME is NULL the
* directory for the current user is returned. Caller must release
* the returned string. */