aboutsummaryrefslogtreecommitdiffstats
path: root/common/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-10-20 14:38:06 +0000
committerWerner Koch <[email protected]>2020-10-20 14:38:06 +0000
commit18e5dd7b03ced51611c9ba1345cf498a0aaf14a6 (patch)
treefaeb1e27f9ffdb049f2e0dec728229d9fd7703b6 /common/sysutils.c
parentReplace most calls to open by a new wrapper. (diff)
downloadgnupg-18e5dd7b03ced51611c9ba1345cf498a0aaf14a6.tar.gz
gnupg-18e5dd7b03ced51611c9ba1345cf498a0aaf14a6.zip
Replace all calls to stat by gnupg_stat.
* common/sysutils.c (gnupg_stat): New. * common/sysutils.h: Include sys/stat.h. -- Yet another wrapper for Unicode support on Windows. GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/sysutils.c')
-rw-r--r--common/sysutils.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index bfb5d7dd8..f8c3a5857 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -1078,6 +1078,49 @@ gnupg_access (const char *name, int mode)
#endif
}
+
+/* A wrapper around stat to handle Unicode file names under Windows. */
+#ifdef HAVE_STAT
+int
+gnupg_stat (const char *name, struct stat *statbuf)
+{
+# ifdef HAVE_W32_SYSTEM
+ if (any8bitchar (name))
+ {
+ wchar_t *wname;
+ struct _stat32 st32;
+ int ret;
+
+ wname = utf8_to_wchar (name);
+ if (!wname)
+ return -1;
+ ret = _wstat (wname, &st32);
+ xfree (wname);
+ if (!ret)
+ {
+ statbuf->st_dev = st32.st_dev;
+ statbuf->st_ino = st32.st_ino;
+ statbuf->st_mode = st32.st_mode;
+ statbuf->st_nlink = st32.st_nlink;
+ statbuf->st_uid = st32.st_uid;
+ statbuf->st_gid = st32.st_gid;
+ statbuf->st_rdev = st32.st_rdev;
+ statbuf->st_size = st32.st_size;
+ statbuf->st_atime = st32.st_atime;
+ statbuf->st_mtime = st32.st_mtime;
+ statbuf->st_ctime = st32.st_ctime;
+ }
+ return ret;
+ }
+ else
+ return stat (name, statbuf);
+# else
+ return stat (name, statbuf);
+# endif
+}
+#endif /*HAVE_STAT*/
+
+
/* A wrapper around open to handle Unicode file names under Windows. */
int
gnupg_open (const char *name, int flags, unsigned int mode)