From 788d17f13392b994a2822d059bf5a7c742606832 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 29 Feb 2020 20:00:53 -0800 Subject: [PATCH] Always use readdir() and not readdir_r(). Most all systems have a thread-safe implementation of readdir() provided they use their own DIR stream. --- configure.ac | 2 +- src/commands.c | 24 ------------------------ 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index 1b935358..2c04884e 100644 --- a/configure.ac +++ b/configure.ac @@ -177,7 +177,7 @@ AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK AC_FUNC_STRFTIME AC_CHECK_FUNCS([memset mkdir munmap setlocale socket strchr strerror strrchr \ strstr strtol setrlimit mlockall getopt_long backtrace \ - getpwnam_r getgrnam_r flock readdir_r clock_gettime getcwd \ + getpwnam_r getgrnam_r flock clock_gettime getcwd \ isascii memchr memmove pathconf putenv select strcasecmp \ strncasecmp strrchr strtoul explicit_bzero memset_s]) AM_CONDITIONAL([NEED_GETOPT_LONG], [test "$ac_cv_func_getopt_long" != "yes"]) diff --git a/src/commands.c b/src/commands.c index 65970915..27f0d923 100644 --- a/src/commands.c +++ b/src/commands.c @@ -4094,12 +4094,7 @@ ls_command (assuan_context_t ctx, char *line) DIR *d; char *list = NULL; char **v = NULL; -#ifdef HAVE_READDIR_R - size_t len; - struct dirent *cur = NULL, *p; -#else struct dirent *cur = NULL; -#endif struct argv_s *args[] = { &(struct argv_s) {"verbose", OPTION_TYPE_NOARG, parse_opt_verbose}, NULL @@ -4124,27 +4119,11 @@ ls_command (assuan_context_t ctx, char *line) return send_error (ctx, rc); } -#ifdef HAVE_READDIR_R - len = offsetof (struct dirent, d_name) + pathconf (dir, _PC_NAME_MAX) + 1; - p = xmalloc (len); - if (!p) - { - xfree (dir); - closedir (d); - return send_error (ctx, GPG_ERR_ENOMEM); - } - pthread_cleanup_push (xfree, p); -#endif - pthread_cleanup_push ((void *)closedir, d); xfree (dir); rc = 0; -#ifdef HAVE_READDIR_R - while (!readdir_r (d, p, &cur) && cur) -#else while ((cur = readdir (d))) -#endif { char **vtmp; struct stat st; @@ -4179,9 +4158,6 @@ ls_command (assuan_context_t ctx, char *line) } pthread_cleanup_pop (1); // closedir (d) -#ifdef HAVE_READDIR_R - pthread_cleanup_pop (1); // xfree (p) -#endif if (rc && rc != GPG_ERR_ENODEV) { -- 2.11.4.GIT