Replace deprecated readdir_r with readdir 42/105342/4
authorKyungwook Tak <k.tak@samsung.com>
Fri, 16 Dec 2016 04:22:32 +0000 (13:22 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Mon, 19 Dec 2016 11:11:54 +0000 (20:11 +0900)
Change-Id: I10857c628068c2a53978c16670fab1f9f9d23033
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/manager/service/for-each-file.cpp
src/manager/service/ss-migrate.cpp

index d992e4d..0121547 100644 (file)
@@ -50,9 +50,8 @@ void forEachFile(const std::string &dirpath, ActionFunc func)
        if (!pEntry)
                ThrowErr(Exc::InternalError, "Memory allocation failed for dir entry");
 
-       struct dirent *pDirEntry = nullptr;
 
-       while ((!readdir_r(dirp.get(), pEntry.get(), &pDirEntry)) && pDirEntry) {
+       while (struct dirent *pDirEntry = readdir(dirp.get())) {
                /* run func for every file names in dirpath. d_name is only file name, not path */
                func(pDirEntry->d_name);
        }
index efadd2f..635c10c 100644 (file)
@@ -96,14 +96,15 @@ void visit_dir(const std::string &dirpath, struct dirent *buf, size_t depth,
        }
 
        while (true) {
-               struct dirent *result = nullptr;
-               auto ret = ::readdir_r(dirptr.get(), buf, &result);
-               if (ret != 0) {
-                       LogError("readdir_r error on secure-storage dir: " << dirpath <<
-                                        " with errno: " << errno);
-                       break;
-               } else if (result == nullptr) {
-                       remove_path(dirpath, isAdminUser);
+               errno = 0;
+               struct dirent *result = ::readdir(dirptr.get());
+               if (result == nullptr) {
+                       if (errno != 0)
+                               LogError("readdir error on secure-storage dir: " << dirpath <<
+                                                " with errno: " << errno);
+                       else
+                               remove_path(dirpath, isAdminUser); // end of stream
+
                        break;
                }