72 struct dirent* entry = NULL;
81 n_log(
LOG_ERR,
"cannot open directory: %s, %s", dir, strerror(error));
84 if (chdir(dir) == -1) {
86 n_log(
LOG_ERR,
"cannot chdir to directory %s, %s", dir, strerror(error));
91 while ((entry = readdir(dp)) != NULL) {
92 if (stat(entry->d_name, &statbuf) != -1) {
94 if (S_ISDIR(statbuf.st_mode)) {
95 if (strcmp(
".", entry->d_name) == 0 || strcmp(
"..", entry->d_name) == 0) {
99 if (recurse != FALSE) {
100 if (
n_scan_dir(entry->d_name, result, recurse) == FALSE) {
101 n_log(
LOG_ERR, entry->d_name,
"error while recursively scanning %s", entry->d_name);
104 }
else if (S_ISREG(statbuf.st_mode)) {
107 file->
name = strdup(entry->d_name);
108#if defined(__linux__)
112 file->
filetime = statbuf.st_mtim.tv_sec;
121 n_log(
LOG_ERR,
"Not a S_ISDIR or S_ISREG file: %s", entry->d_name);
125 n_log(
LOG_ERR,
"unable to stat %s, %s", entry->d_name, strerror(error));
131 if (chdir(
"..") == -1) {
133 n_log(
LOG_ERR,
"cannot chdir back to parent from %s, %s", dir, strerror(error));
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
int list_push_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
Add a pointer sorted in the list , starting by the end of the list.
Structure of a generic LIST container.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
time_t filetime
file creation time
int n_scan_dir(const char *dir, LIST *result, const int recurse)
Scan given directory and return a LIST of char.
void n_free_file_info(void *ptr)
free a N_FILE_INFO struct
static int n_comp_file_info(const void *a, const void *b)
local comparison function for sorting filenames, case insensitive
Files configuration header.