49 if( f1 -> filetime < f2 -> filetime )
53 else if( f1 -> filetime == f2 -> filetime )
55 if( f1 -> filetime_nsec < f2 -> filetime_nsec )
59 else if( f1 -> filetime_nsec > f2 -> filetime_nsec )
64 else if( f1 -> filetime > f2 -> filetime )
85 struct dirent *entry = NULL;
95 n_log(
LOG_ERR ,
"cannot open directory: %s, %s" , dir , strerror( error ) );
98 if( chdir( dir ) == -1 )
101 n_log(
LOG_ERR ,
"cannot chdir to directory %s, %s" , dir , strerror( error ) );
106 while( ( entry = readdir( dp ) ) != NULL )
108 if( stat( entry -> d_name , &statbuf ) != -1 )
111 if( S_ISDIR( statbuf . st_mode ) )
113 if( strcmp(
"." , entry -> d_name ) == 0 || strcmp(
".." , entry -> d_name ) == 0 )
118 if( recurse != FALSE )
120 if(
n_scan_dir( entry -> d_name , result, recurse ) == FALSE )
122 n_log(
LOG_ERR , entry -> d_name ,
"error while recursively scanning %s" , entry -> d_name );
126 else if( S_ISREG( statbuf . st_mode ) )
130 file -> name = strdup( entry -> d_name );
132 file -> filetime = statbuf . st_mtime ;
133 file -> filetime_nsec = statbuf . st_mtimensec ;
135 file -> filetime = statbuf . st_mtim . tv_sec ;
136 file -> filetime_nsec = statbuf . st_mtim . tv_nsec ;
138 file -> filetime = statbuf . st_mtime ;
139 file -> filetime_nsec = 0 ;
146 n_log(
LOG_ERR ,
"Not a S_ISDIR or S_ISREG file: %s" , entry -> d_name );
152 n_log(
LOG_ERR ,
"unable to stat %s, %s" , entry -> d_name , strerror( error ) );
157 n_log(
LOG_ERR ,
"readdir failed: %s" , strerror( error ) );
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.
int n_scan_dir(const char *dir, LIST *result, const int recurse)
Scan given directory and return a LIST of char.
static int n_comp_file_info(const void *a, const void *b)
local comparison function for sorting filenames, case insensitive