From: Thomas Jarosch Date: Mon, 17 Oct 2011 09:53:37 +0000 (+0200) Subject: Replace readdir() by thread-safe readdir_r() function X-Git-Tag: v2.6~28 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=10c3af2d66424a6693c0be0883d3812b39f58df9;p=libi2ncommon Replace readdir() by thread-safe readdir_r() function --- 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;