From 76f2e3f18f933989a372183526178bbb6d2fd587 Mon Sep 17 00:00:00 2001
From: "alexey.stratulat" <alexey.stratulat@demlabs.net>
Date: Mon, 20 Jan 2020 14:02:52 +0700
Subject: [PATCH] [+] Added function has been added to identify all
 subdirectories in a directory in the Linux family operating system.

---
 include/dap_file_utils.h |  4 ++++
 src/dap_file_utils.c     | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/dap_file_utils.h b/include/dap_file_utils.h
index 81e22d8..2a85b16 100755
--- a/include/dap_file_utils.h
+++ b/include/dap_file_utils.h
@@ -22,6 +22,8 @@
  along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include <stdbool.h>
+#include "dap_list.h"
+#include <dirent.h>
 
 #ifndef _DAP_FILE_UTILS_H_
 #define _DAP_FILE_UTILS_H_
@@ -85,4 +87,6 @@ char* dap_path_get_basename(const char *a_file_name);
 bool  dap_path_is_absolute(const char *a_file_name);
 char* dap_path_get_dirname(const char *a_file_name);
 
+dap_list_t *dap_dir_get_subdirectory(const char *a_path_name);
+
 #endif // _FILE_UTILS_H_
diff --git a/src/dap_file_utils.c b/src/dap_file_utils.c
index 2ad83ad..3826922 100755
--- a/src/dap_file_utils.c
+++ b/src/dap_file_utils.c
@@ -368,3 +368,17 @@ char* dap_path_get_dirname(const char *a_file_name)
 
     return l_base;
 }
+
+dap_list_t *dap_dir_get_subdirectory(const char *a_path_dir){
+    dap_list_t *list = dap_list_alloc();
+    DIR *dir = opendir(a_path_dir);
+    struct dirent *entry = readdir(dir);
+    while (entry != NULL){
+        if (strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name, ".") != 0 && entry->d_type == DT_DIR){
+            dap_list_append(list, entry->d_name);
+        }
+        entry = readdir(dir);
+    }
+    closedir(dir);
+    return list;
+}
-- 
GitLab