47 if (f1->filetime_nsec < f2->filetime_nsec) {
49 }
else if (f1->filetime_nsec > f2->filetime_nsec) {
71 struct dirent* entry = NULL;
80 n_log(
LOG_ERR,
"cannot open directory: %s, %s", dir, strerror(error));
83 if (chdir(dir) == -1) {
85 n_log(
LOG_ERR,
"cannot chdir to directory %s, %s", dir, strerror(error));
90 while ((entry = readdir(dp)) != NULL) {
91 if (stat(entry->d_name, &statbuf) != -1) {
93 if (S_ISDIR(statbuf.st_mode)) {
94 if (strcmp(
".", entry->d_name) == 0 || strcmp(
"..", entry->d_name) == 0) {
98 if (recurse != FALSE) {
99 if (
n_scan_dir(entry->d_name, result, recurse) == FALSE) {
100 n_log(
LOG_ERR, entry->d_name,
"error while recursively scanning %s", entry->d_name);
103 }
else if (S_ISREG(statbuf.st_mode)) {
106 file->
name = strdup(entry->d_name);
109 file->filetime_nsec = statbuf.st_mtimensec;
111 file->
filetime = statbuf.st_mtim.tv_sec;
112 file->filetime_nsec = statbuf.st_mtim.tv_nsec;
115 file->filetime_nsec = 0;
120 n_log(
LOG_ERR,
"Not a S_ISDIR or S_ISREG file: %s", entry->d_name);
124 n_log(
LOG_ERR,
"unable to stat %s, %s", entry->d_name, strerror(error));
130 if (chdir(
"..") == -1) {
132 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