Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap
1 result
Show changes
Commits on Source (10)
......@@ -22,6 +22,7 @@
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#define _XOPEN_SOURCE 700
#pragma once
......
......@@ -22,12 +22,16 @@
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_
#ifdef _WIN32
#include <Windows.h>
/* On Win32, the canonical directory separator is the backslash, and
* the search path separator is the semicolon. Note that also the
* (forward) slash works as directory separator.
......@@ -85,4 +89,12 @@ 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);
/**
* Get list of subdirectories
*
* @a_path_name directory path.
* @return dap_list_t type variable that contains a list of subdirectories.
*/
dap_list_t *dap_get_subs(const char *a_path_name);
#endif // _FILE_UTILS_H_
......@@ -21,7 +21,6 @@
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* 'nanosleep' */
......
......@@ -368,3 +368,34 @@ char* dap_path_get_dirname(const char *a_file_name)
return l_base;
}
dap_list_t *dap_get_subs(const char *a_path_dir){
dap_list_t *list = dap_list_alloc();
#ifdef _WIN32
size_t m_size = strlen(a_path_dir);
char *m_path = DAP_NEW_SIZE(char, m_size + 2);
memcpy(m_path, a_path_dir, m_size);
m_path[m_size] = '*';
m_path[m_size + 1] = '\0';
WIN32_FIND_DATA info_file;
HANDLE h_find_file = FindFirstFileA(m_path, &info_file);
while (FindNextFileA(h_find_file, &info_file)){
if (info_file.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
dap_list_append(list, info_file.cFileName);
}
}
FindClose(h_find_file);
DAP_FREE(m_path);
#else
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);
#endif
return list;
}
......@@ -13,31 +13,31 @@ wchar_t* readRegKey(HKEY hKey, LPCWSTR regSubKey, LPCWSTR val) {
}
char* regGetUsrPath() {
static char path[MAX_PATH] = {};
static char path[MAX_PATH] = {'\0'};
if (strlen(path) > 3) { return path; }
HKEY hKey;
const char keyPath[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
LSTATUS err = RegOpenKeyExA(HKEY_CURRENT_USER,
LSTATUS err = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
keyPath,
0, KEY_READ, &hKey );
if (err != ERROR_SUCCESS) { return NULL; }
DWORD len = MAX_PATH;
err = RegGetValueA(hKey, NULL, "Personal", RRF_RT_REG_SZ, NULL, (void*)path, &len);
err = RegGetValueA(hKey, NULL, "Common Documents", RRF_RT_REG_SZ, NULL, (void*)path, &len);
RegCloseKey(hKey);
return path;
}
wchar_t* regWGetUsrPath() {
static wchar_t path[MAX_PATH] = {};
static wchar_t path[MAX_PATH] = {'\0'};
if (wcslen(path) > 3) { return path; }
HKEY hKey;
const char keyPath[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
LSTATUS err = RegOpenKeyExA(HKEY_CURRENT_USER,
LSTATUS err = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
keyPath,
0, KEY_READ, &hKey );
if (err != ERROR_SUCCESS) { return NULL; }
DWORD len = MAX_PATH;
err = RegGetValueW(hKey, NULL, L"Personal", RRF_RT_REG_SZ, NULL, (void*)path, &len);
err = RegGetValueW(hKey, NULL, L"Common Documents", RRF_RT_REG_SZ, NULL, (void*)path, &len);
RegCloseKey(hKey);
return path;
}
......