Replace readdir() by thread-safe readdir_r() function
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 17 Oct 2011 09:53:37 +0000 (11:53 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 17 Oct 2011 09:53:37 +0000 (11:53 +0200)
src/filefunc.cpp

index a753324..0836d37 100644 (file)
@@ -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;