Skip to content
Snippets Groups Projects
Commit a67c1ed7 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

[*] Fix. Dap_get_subs function no longer returns dap_list, but returns the...

[*] Fix. Dap_get_subs function no longer returns dap_list, but returns the dap_list_name_directories_t structure which is a single-linked list containing the name of directories. To work with this structure, utlist is used.
parent 412970a9
No related branches found
No related tags found
1 merge request!36[*] Fix. Dap_get_subs function no longer returns dap_list, but returns the...
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdbool.h> #include <stdbool.h>
#include "dap_list.h" #include "utlist.h"
#include <dirent.h> #include <dirent.h>
#ifndef _DAP_FILE_UTILS_H_ #ifndef _DAP_FILE_UTILS_H_
...@@ -52,6 +52,11 @@ ...@@ -52,6 +52,11 @@
#endif #endif
typedef struct dap_list_name_directories{
char *name_directory;
struct dap_list_name_directories *next;
}dap_list_name_directories_t;
/** /**
* Check the directory path for unsupported symbols * Check the directory path for unsupported symbols
* *
...@@ -95,6 +100,6 @@ char* dap_path_get_dirname(const char *a_file_name); ...@@ -95,6 +100,6 @@ char* dap_path_get_dirname(const char *a_file_name);
* @a_path_name directory path. * @a_path_name directory path.
* @return dap_list_t type variable that contains a list of subdirectories. * @return dap_list_t type variable that contains a list of subdirectories.
*/ */
dap_list_t *dap_get_subs(const char *a_path_name); dap_list_name_directories_t *dap_get_subs(const char *a_path_name);
#endif // _FILE_UTILS_H_ #endif // _FILE_UTILS_H_
...@@ -369,8 +369,9 @@ char* dap_path_get_dirname(const char *a_file_name) ...@@ -369,8 +369,9 @@ char* dap_path_get_dirname(const char *a_file_name)
return l_base; return l_base;
} }
dap_list_t *dap_get_subs(const char *a_path_dir){ dap_list_name_directories_t *dap_get_subs(const char *a_path_dir){
dap_list_t *list = dap_list_alloc(); dap_list_name_directories_t *list = NULL;
dap_list_name_directories_t *element;
#ifdef _WIN32 #ifdef _WIN32
size_t m_size = strlen(a_path_dir); size_t m_size = strlen(a_path_dir);
char *m_path = DAP_NEW_SIZE(char, m_size + 2); char *m_path = DAP_NEW_SIZE(char, m_size + 2);
...@@ -381,7 +382,9 @@ dap_list_t *dap_get_subs(const char *a_path_dir){ ...@@ -381,7 +382,9 @@ dap_list_t *dap_get_subs(const char *a_path_dir){
HANDLE h_find_file = FindFirstFileA(m_path, &info_file); HANDLE h_find_file = FindFirstFileA(m_path, &info_file);
while (FindNextFileA(h_find_file, &info_file)){ while (FindNextFileA(h_find_file, &info_file)){
if (info_file.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){ if (info_file.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
dap_list_append(list, info_file.cFileName); element = (list_name_directories_t *)malloc(sizeof(list_name_directories_t));
element->name_directory = dap_strdup(info_file.cFileName);
LL_APPEND(list, element);
} }
} }
FindClose(h_find_file); FindClose(h_find_file);
...@@ -391,7 +394,9 @@ dap_list_t *dap_get_subs(const char *a_path_dir){ ...@@ -391,7 +394,9 @@ dap_list_t *dap_get_subs(const char *a_path_dir){
struct dirent *entry = readdir(dir); struct dirent *entry = readdir(dir);
while (entry != NULL){ while (entry != NULL){
if (strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name, ".") != 0 && entry->d_type == DT_DIR){ if (strcmp(entry->d_name, "..") != 0 && strcmp(entry->d_name, ".") != 0 && entry->d_type == DT_DIR){
dap_list_append(list, entry->d_name); element = (dap_list_name_directories_t *)malloc(sizeof(dap_list_name_directories_t));
element->name_directory = dap_strdup(entry->d_name);
LL_APPEND(list, element);
} }
entry = readdir(dir); entry = readdir(dir);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment