From 364cef997c0ac5632152acfb7ab2330c4f289a9a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Sat, 22 Aug 2020 14:37:44 +0200 Subject: [PATCH] common: Use gpgrt functions for mkdir and chdir if available * common/sysutils.c (gnupg_mkdir): Divert to gpgrt_mkdir. (gnupg_chdir): Divert to gpgrt_chdir -- To avoid bumping up the build dependency on libgpg-error 1.28 we use the gpgrt version only if at least this libgpg-error version was used at build time. This won't fix any bugs though and it is in general advisable to use the latest libgpg-error. There are actually a couple of very useful bug fixes for Windows in the upcoming libgpg-error 1.39 but on Unix you can live without them. Signed-off-by: Werner Koch --- common/sysutils.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/common/sysutils.c b/common/sysutils.c index 0a3dc2eaf..2673e4556 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -768,7 +768,8 @@ modestr_to_mode (const char *modestr) int gnupg_mkdir (const char *name, const char *modestr) { -#ifdef HAVE_W32CE_SYSTEM +#if GPG_ERROR_VERSION_NUMBER < 0x011c00 /* 1.28 */ + #ifdef HAVE_W32CE_SYSTEM wchar_t *wname; (void)modestr; @@ -782,14 +783,19 @@ gnupg_mkdir (const char *name, const char *modestr) } xfree (wname); return 0; -#elif MKDIR_TAKES_ONE_ARG + #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. */ return mkdir (name); -#else + #else return mkdir (name, modestr_to_mode (modestr)); + #endif +#else + /* Note that gpgrt_mkdir also sets ERRNO in addition to returing an + * gpg-error style error code. */ + return gpgrt_mkdir (name, modestr); #endif } @@ -799,7 +805,13 @@ gnupg_mkdir (const char *name, const char *modestr) int gnupg_chdir (const char *name) { +#if GPG_ERROR_VERSION_NUMBER < 0x011c00 /* 1.28 */ return chdir (name); +#else /* Use the improved version from libgpg_error. */ + /* Note that gpgrt_chdir also sets ERRNO in addition to returing a + * gpg-error style error code. */ + return gpgrt_chdir (name); +#endif }