Fix issues shown by cppcheck for wrt-plugins-common
[platform/framework/web/wrt-plugins-common.git] / src / modules / tizen / Filesystem / Node.cpp
index d345dd0..eddbe19 100644 (file)
@@ -44,7 +44,7 @@ INodePtr Node::resolve(const IPathPtr& path)
                  "Node does not exist or access denied.");
     }
 
-    if (!S_ISDIR(info.st_mode) & !S_ISREG(info.st_mode)) {
+    if (!S_ISDIR(info.st_mode) && !S_ISREG(info.st_mode)) {
         ThrowMsg(Commons::PlatformException,
                  "Platform node is of unsupported type.");
     }
@@ -100,16 +100,20 @@ Node::NameList Node::getChildNames() const
 
     NameList result;
     errno = 0;
-    struct dirent *entry = NULL;
-    while ((entry = readdir(dir))) {
-        if (!strncmp(entry->d_name, ".",
-                     1) || !strncmp(entry->d_name, "..", 2))
+    int return_code;
+    struct dirent entry;
+    struct dirent *entry_result;
+    for (return_code = readdir_r(dir, &entry, &entry_result);
+            entry_result != NULL && return_code != 0;
+            return_code = readdir_r(dir, &entry, &entry_result)) {
+        if (!strncmp(entry.d_name, ".", 1) ||
+            !strncmp(entry.d_name, "..", 2))
         {
             continue;
         }
-        result.push_back(entry->d_name);
+        result.push_back(entry.d_name);
     }
-    if (errno != 0) {
+    if (return_code != 0 || errno != 0) {
         ThrowMsg(Commons::PlatformException, "Error while reading directory.");
     }
 
@@ -138,16 +142,20 @@ NodeList Node::getChildNodes(const NodeFilterPtr& filter) const
 
     errno = 0;
     NodeList result;
-    struct dirent *entry = NULL;
-    while ((entry = readdir(dir))) {
-        if (!strncmp(entry->d_name, ".",
-                     1) || !strncmp(entry->d_name, "..", 2))
+    int return_code;
+    struct dirent entry;
+    struct dirent *entry_result;
+    for (return_code = readdir_r(dir, &entry, &entry_result);
+            entry_result != NULL && return_code != 0;
+            return_code = readdir_r(dir, &entry, &entry_result)) {
+        if (!strncmp(entry.d_name, ".", 1) ||
+            !strncmp(entry.d_name, "..", 2))
         {
             continue;
         }
         Try {
             Assert(m_path);
-            INodePtr node = Node::resolve(*m_path + entry->d_name);
+            INodePtr node = Node::resolve(*m_path + entry.d_name);
             node->setPermissions(getPermissions()); // inherit access rights
             if (NodeFilterMatcher::match(node, filter)) {
                 result.push_back(node);
@@ -156,7 +164,7 @@ NodeList Node::getChildNodes(const NodeFilterPtr& filter) const
         Catch(Commons::PlatformException) {}
     }
 
-    if (errno != 0) {
+    if (return_code != 0 || errno != 0) {
         ThrowMsg(Commons::PlatformException, "Error while reading directory.");
     }