From 10c3af2d66424a6693c0be0883d3812b39f58df9 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Mon, 17 Oct 2011 11:53:37 +0200 Subject: [PATCH] Replace readdir() by thread-safe readdir_r() function --- src/filefunc.cpp | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/filefunc.cpp b/src/filefunc.cpp index a753324..0836d37 100644 --- a/src/filefunc.cpp +++ b/src/filefunc.cpp @@ -44,7 +44,6 @@ on this file might be covered by the GNU General Public License. #include "filefunc.hxx" #include "stringfunc.hxx" - namespace I2n { @@ -270,8 +269,8 @@ bool get_dir( { return false; } - struct dirent *entry; - while ( NULL != (entry = ::readdir(dir)) ) + struct dirent store, *entry = NULL; + while (readdir_r(dir, &store, &entry) == 0 && entry != NULL) { std::string name( entry->d_name ); if (! include_dot_names && (name[0] == '.') ) @@ -709,8 +708,9 @@ bool recursive_delete(const std::string &path, std::string *error) throw runtime_error("can't open directory " + path); } - struct dirent *entry; - while ((entry = readdir(dir))) { + struct dirent store, *entry = NULL; + while (readdir_r(dir, &store, &entry) == 0 && entry != NULL) + { string filename = entry->d_name; if (filename == "." || filename == "..") { continue; -- 1.7.1