diff options
Diffstat (limited to 'src/lib.c')
-rw-r--r-- | src/lib.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib.c b/src/lib.c new file mode 100644 index 0000000..f43bdc2 --- /dev/null +++ b/src/lib.c @@ -0,0 +1,48 @@ +#include "lib.h" +#include "util.h" + +int +collect_library(char *** dst, char * argv[], int argc, int optind) +{ + int n = 0; + FILE *fp; + char path[1035]; + + char ** lib = NULL; + + for (int i = optind; i < argc; i++) { + lib = realloc(lib, sizeof(char **) * (n + 1)); + lib[n] = strdup(argv[i]); + fdebug("%d: %s\n", n, lib[n]); + n = n + 1; + } + + fp = popen("/bin/find /home/gramanas/code/foodtools/lib/ -name '*.rcp'", "r"); + if (fp == NULL) { + fprintf(stderr, "Couldn't run /bin/find\n"); + exit(1); + } + + /* Read the output a line at a time */ + while (fgets(path, sizeof(path), fp) != NULL) { + lib = realloc(lib, sizeof(char **) * (n + 1)); + trim(path); + lib[n] = strdup(path); + fdebug("%d: %s\n", n, lib[n]); + n = n + 1; + } + + /* close */ + pclose(fp); + + *dst = lib; + return n; // no of items +} + +void +free_library(char ** lib, int n) { + for (int i = 0; i < n; i++) { + free(lib[i]); + } + free(lib); +} |