1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

common: New functions gnupg_opendir et al.

* common/sysutils.h (struct gnupg_dirent_s): New.
* common/sysutils.c: Include dirent.h.
(struct gnupg_dir_s): New.
(gnupg_opendir, gnupg_readdir, gnupg_closedir): New.  Change all
callers of opendir, readdir, and closedir to use these functions.
--

GnuPG-bug-id: 5098
This commit is contained in:
Werner Koch 2020-10-21 16:59:38 +02:00
parent 9a0197b6fe
commit 7e22e08e2a
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
9 changed files with 217 additions and 43 deletions

View file

@ -101,10 +101,6 @@
#ifndef HAVE_W32_SYSTEM
#include <sys/utsname.h>
#endif
#ifdef MKDIR_TAKES_ONE_ARG
#undef mkdir
#define mkdir(a,b) mkdir(a)
#endif
#include "dirmngr.h"
#include "validate.h"
@ -206,15 +202,15 @@ get_current_cache (void)
static int
create_directory_if_needed (const char *name)
{
DIR *dir;
gnupg_dir_t dir;
char *fname;
fname = make_filename (opt.homedir_cache, name, NULL);
dir = opendir (fname);
dir = gnupg_opendir (fname);
if (!dir)
{
log_info (_("creating directory '%s'\n"), fname);
if (mkdir (fname, S_IRUSR|S_IWUSR|S_IXUSR) )
if (gnupg_mkdir (fname, "-rwx"))
{
int save_errno = errno;
log_error (_("error creating directory '%s': %s\n"),
@ -225,7 +221,7 @@ create_directory_if_needed (const char *name)
}
}
else
closedir (dir);
gnupg_closedir (dir);
xfree (fname);
return 0;
}
@ -237,8 +233,8 @@ static int
cleanup_cache_dir (int force)
{
char *dname = make_filename (opt.homedir_cache, DBDIR_D, NULL);
DIR *dir;
struct dirent *de;
gnupg_dir_t dir;
gnupg_dirent_t de;
int problem = 0;
if (!force)
@ -251,7 +247,7 @@ cleanup_cache_dir (int force)
}
}
dir = opendir (dname);
dir = gnupg_opendir (dname);
if (!dir)
{
log_error (_("error reading directory '%s': %s\n"),
@ -260,7 +256,7 @@ cleanup_cache_dir (int force)
return -1;
}
while ((de = readdir (dir)))
while ((de = gnupg_readdir (dir)))
{
if (strcmp (de->d_name, "." ) && strcmp (de->d_name, ".."))
{
@ -289,7 +285,7 @@ cleanup_cache_dir (int force)
}
}
xfree (dname);
closedir (dir);
gnupg_closedir (dir);
return problem;
}