diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/mkdir_p.c | 2 | ||||
-rw-r--r-- | common/sysutils.c | 43 | ||||
-rw-r--r-- | common/sysutils.h | 6 |
3 files changed, 50 insertions, 1 deletions
diff --git a/common/mkdir_p.c b/common/mkdir_p.c index c26cfee01..6fb98c370 100644 --- a/common/mkdir_p.c +++ b/common/mkdir_p.c @@ -78,7 +78,7 @@ gnupg_amkdir_p (const char **directory_components) /* log_debug ("%s: stat(%s)\n", __func__, dirs[i]); */ - if (!stat (dirs[i], &s)) + if (!gnupg_stat (dirs[i], &s)) { if ( ! S_ISDIR (s.st_mode)) { diff --git a/common/sysutils.c b/common/sysutils.c index e06be057f..842efb975 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -1107,6 +1107,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) diff --git a/common/sysutils.h b/common/sysutils.h index aabd15f8b..1862926ef 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -46,6 +46,9 @@ typedef int gnupg_fd_t; #define FD2INT(h) (h) #endif +#ifdef HAVE_STAT +# include <sys/stat.h> +#endif void trap_unaligned (void); int disable_core_dumps (void); @@ -73,6 +76,9 @@ int gnupg_setenv (const char *name, const char *value, int overwrite); int gnupg_unsetenv (const char *name); char *gnupg_getcwd (void); gpg_err_code_t gnupg_access (const char *name, int mode); +#ifdef HAVE_STAT +int gnupg_stat (const char *name, struct stat *statbuf); +#endif /*HAVE_STAT*/ int gnupg_open (const char *name, int flags, unsigned int mode); char *gnupg_get_socket_name (int fd); int gnupg_fd_valid (int fd); |