From e44ac1094eaba6b7ca59d5b2539d660c44bba5c3 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Tue, 14 Jan 2020 11:32:45 -0500 Subject: initial commit --- sources.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sources.c (limited to 'sources.c') diff --git a/sources.c b/sources.c new file mode 100644 index 0000000..3defa73 --- /dev/null +++ b/sources.c @@ -0,0 +1,38 @@ +#define _XOPEN_SOURCE 700 +#include +#include +#include + +#include "maje.h" + +static char **filelist = NULL; +static size_t nfiles = 0; + +static int addfile(const char *path, const struct stat *st, int flags, struct FTW *ft) +{ + (void)st; (void)flags; (void)ft; + + if (path[0] == '.' && path[1] == '/') { + path += 2; + } + + if (strcmp(path + strlen(path) - 2, ".c") == 0) { + char **tmp = realloc(filelist, sizeof(*filelist) * (nfiles + 2)); + if (tmp == NULL) { + return 1; + } + filelist = tmp; + + filelist[nfiles] = strdup(path); + filelist[nfiles + 1] = NULL; + nfiles++; + } + + return 0; +} + +char ** find_source_files(const char *dir) +{ + nftw(dir, addfile, -1, 0); + return filelist; +} -- cgit v1.2.1