From ef68a24f9dbb9ea7d29d8c3ef483b136f49c6cb0 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Jan 2020 15:56:22 -0500 Subject: use a struct to cache stat() information --- sources.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'sources.c') diff --git a/sources.c b/sources.c index 3defa73..0963bc9 100644 --- a/sources.c +++ b/sources.c @@ -5,7 +5,7 @@ #include "maje.h" -static char **filelist = NULL; +static struct majefile **filelist = NULL; static size_t nfiles = 0; static int addfile(const char *path, const struct stat *st, int flags, struct FTW *ft) @@ -17,21 +17,24 @@ static int addfile(const char *path, const struct stat *st, int flags, struct FT } if (strcmp(path + strlen(path) - 2, ".c") == 0) { - char **tmp = realloc(filelist, sizeof(*filelist) * (nfiles + 2)); + struct majefile **tmp = realloc(filelist, sizeof(*filelist) * (nfiles + 2)); if (tmp == NULL) { return 1; } filelist = tmp; - filelist[nfiles] = strdup(path); - filelist[nfiles + 1] = NULL; + filelist[nfiles] = malloc(sizeof(*filelist[nfiles]) + strlen(path) + 1); + + filelist[nfiles]->st = *st; + strcpy(filelist[nfiles]->path, strdup(path)); + //filelist[nfiles + 1] = NULL; nfiles++; } return 0; } -char ** find_source_files(const char *dir) +struct majefile ** find_source_files(const char *dir) { nftw(dir, addfile, -1, 0); return filelist; -- cgit v1.2.1