summaryrefslogtreecommitdiff
path: root/sources.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-01-14 15:56:22 -0500
committerJakob Kaivo <jkk@ung.org>2020-01-14 15:56:22 -0500
commitef68a24f9dbb9ea7d29d8c3ef483b136f49c6cb0 (patch)
tree058c2c8b24de405751eb5b74913c020c4f0294f3 /sources.c
parentf2263ff211aba3e6af4658b416f3a7bef7dcc852 (diff)
use a struct to cache stat() information
Diffstat (limited to 'sources.c')
-rw-r--r--sources.c13
1 files changed, 8 insertions, 5 deletions
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;