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 <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-08-22 14:37:44 +02:00
parent bef68efd8d
commit 364cef997c
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 15 additions and 3 deletions

View File

@ -768,7 +768,8 @@ modestr_to_mode (const char *modestr)
int int
gnupg_mkdir (const char *name, const char *modestr) 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; wchar_t *wname;
(void)modestr; (void)modestr;
@ -782,14 +783,19 @@ gnupg_mkdir (const char *name, const char *modestr)
} }
xfree (wname); xfree (wname);
return 0; return 0;
#elif MKDIR_TAKES_ONE_ARG #elif MKDIR_TAKES_ONE_ARG
(void)modestr; (void)modestr;
/* Note: In the case of W32 we better use CreateDirectory and try to /* Note: In the case of W32 we better use CreateDirectory and try to
set appropriate permissions. However using mkdir is easier set appropriate permissions. However using mkdir is easier
because this sets ERRNO. */ because this sets ERRNO. */
return mkdir (name); return mkdir (name);
#else #else
return mkdir (name, modestr_to_mode (modestr)); 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 #endif
} }
@ -799,7 +805,13 @@ gnupg_mkdir (const char *name, const char *modestr)
int int
gnupg_chdir (const char *name) gnupg_chdir (const char *name)
{ {
#if GPG_ERROR_VERSION_NUMBER < 0x011c00 /* 1.28 */
return chdir (name); 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
} }