52 if (dirlist->
path) free(dirlist->
path);
56 for (fi = 0; fi < dirlist->
nfiles; fi++) {
98 "Could not create directory list for: %s\n",
99 " -> memory allocation error\n", path);
104 dirlist->
flags = flags;
106 dirlist->
path = strdup(path);
108 if (!dirlist->
path) {
111 "Could not create directory list for: %s\n",
112 " -> memory allocation error\n", path);
127 "Could not create directory list for: %s\n",
128 " -> memory allocation error\n", path);
155 const char **patterns,
161 if (!npatterns || !patterns) {
165 cflags = REG_EXTENDED | REG_NOSUB;
172 dirlist->
patterns, npatterns, patterns, cflags);
177 "Could not add file patterns for directory: %s\n",
178 " -> regular expression error\n",
185 dirlist->
stats.st_mtime = 0;
212 struct stat dir_stats;
214 struct dirent *direntp;
222 *file_list = (
char **)NULL;
226 if (access(dirlist->
path, F_OK) != 0) {
228 if (errno == ENOENT) {
234 "Could not access directory: %s\n",
235 " -> %s\n", dirlist->
path, strerror(errno));
243 if (stat(dirlist->
path, &dir_stats) != 0 ) {
246 "Could not stat directory: %s\n",
247 " -> %s\n", dirlist->
path, strerror(errno));
252 if (dirlist->
stats.st_mtime == dir_stats.st_mtime) {
253 dirlist->
stats = dir_stats;
260 for (fi = 0; fi < dirlist->
nfiles; fi++) {
269 dirp = opendir(dirlist->
path);
273 "Could not open directory: %s\n",
274 " -> %s\n", dirlist->
path, strerror(errno));
288 if (!(direntp = readdir(dirp))) {
293 "Could not read directory: %s\n",
294 " -> %s\n", dirlist->
path, strerror(errno));
306 if (direntp->d_name[0] ==
'.') {
312 if ((direntp->d_name[1] ==
'\0') ||
313 (direntp->d_name[1] ==
'.' && direntp->d_name[2] ==
'\0')) {
324 dirlist->
patterns, direntp->d_name, 0, NULL, NULL, NULL, NULL);
333 "Could not get file list for directory: %s\n",
334 " -> regular expression error\n",
347 new_list = (
char **)realloc(
348 dirlist->
file_list, new_size *
sizeof(
char *));
353 "Could not get file list for directory: %s\n",
354 " -> memory allocation error\n",
364 for (fi = dirlist->
nfiles; fi < dirlist->nalloced; fi++) {
376 "Could not get file list for directory: %s\n",
377 " -> memory allocation error\n",
389 dirlist->
stats = dir_stats;
423 int (*qsort_compare)(
const void *,
const void *))
426 dirlist->
stats.st_mtime = 0;
int nalloced
allocated length of the file list
#define ARMUTILS_LIB_NAME
ARMUTILS library name.
int make_path(const char *path, mode_t mode)
Make the full path to a directory.
char * path
path to the directory
int dirlist_get_file_list(DirList *dirlist, char ***file_list)
Get the list of files in a directory.
void dirlist_set_qsort_compare(DirList *dirlist, int(*qsort_compare)(const void *, const void *))
Set the file name compare function.
char ** file_list
list of files in the directory
int dirlist_add_patterns(DirList *dirlist, int npatterns, const char **patterns, int ignore_case)
Add file patterns to a directory list.
Regular Expressions List.
int qsort_strcmp(const void *str1, const void *str2)
Qsort string compare function.
DirList * dirlist_create(const char *path, int flags)
Create a new directory list.
int msngr_make_path(const char *path, mode_t mode, size_t errlen, char *errstr)
ARM Utilities Library Header.
#define DL_SHOW_DOT_FILES
include files starting with a '.
void dirlist_free(DirList *dirlist)
Free all memory used by a directory list.
int relist_execute(REList *re_list, const char *string, int eflags, int *mindex, size_t *nsubs, regmatch_t **pmatch, char ***substrings)
Compare a string with a list of regular expressions.
REList * patterns
list of file patterns to look for
struct stat stats
directory stats
void relist_free(REList *re_list)
Free a regular expressions list.
#define ERROR(sender,...)
int(* qsort_compare)(const void *, const void *)
function used by qsort to sort the file list
int nfiles
number of files in the file list
REList * relist_compile(REList *re_list, int npatterns, const char **patterns, int cflags)
Compile a list of regular expression patterns.