[CLASSES]: Introduce cus__load_dir()

To load directory trees, looking for files with a specified glob mask, calling
cus__load() on the ones that match and optionally recursively searching for
more matches in subdirectories.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2006-12-27 14:57:19 -02:00
parent b0e2c51ec8
commit 3ac4b868aa
2 changed files with 52 additions and 0 deletions

View File

@ -9,8 +9,10 @@
#define _GNU_SOURCE
#include <assert.h>
#include <dirent.h>
#include <dwarf.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <libelf.h>
#include <search.h>
#include <stdio.h>
@ -2093,6 +2095,54 @@ next_sibling:
cu__process_die(dwarf, die, cu);
}
int cus__load_dir(struct cus *self, const char *dirname,
const char *filename_mask, const int recursive)
{
struct dirent *entry;
int err = -1;
DIR *dir = opendir(dirname);
if (dir == NULL)
goto out;
err = 0;
while ((entry = readdir(dir)) != NULL) {
char pathname[PATH_MAX];
struct stat st;
if (strcmp(entry->d_name, ".") == 0 ||
strcmp(entry->d_name, "..") == 0)
continue;
snprintf(pathname, sizeof(pathname), "%s/%s",
dirname, entry->d_name);
err = lstat(pathname, &st);
if (err != 0)
break;
if (S_ISDIR(st.st_mode)) {
if (!recursive)
continue;
err = cus__load_dir(self, pathname,
filename_mask, recursive);
if (err != 0)
break;
} else if (fnmatch(filename_mask, entry->d_name, 0) == 0) {
err = cus__load(self, pathname);
if (err != 0)
break;
}
}
if (err == -1)
puts(dirname);
closedir(dir);
out:
return err;
}
int cus__load(struct cus *self, const char *filename)
{
Dwarf_Off offset, last_offset, abbrev_offset;

View File

@ -165,6 +165,8 @@ extern void function__print(const struct function *self, int show_stats,
extern struct cus *cus__new(struct list_head *definitions,
struct list_head *fwd_decls);
extern int cus__load(struct cus *self, const char *filename);
extern int cus__load_dir(struct cus *self, const char *dirname,
const char *filename_mask, const int recursive);
extern struct cu *cus__find_cu_by_name(const struct cus *self,
const char *name);
extern struct function *cus__find_function_by_name(const struct cus *self,