diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-01-14 15:56:22 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-01-14 15:56:22 -0500 |
commit | ef68a24f9dbb9ea7d29d8c3ef483b136f49c6cb0 (patch) | |
tree | 058c2c8b24de405751eb5b74913c020c4f0294f3 /sources.c | |
parent | f2263ff211aba3e6af4658b416f3a7bef7dcc852 (diff) |
use a struct to cache stat() information
Diffstat (limited to 'sources.c')
-rw-r--r-- | sources.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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; |