From 53ab9ae05a579a19c626e8be0c1e2cf9244bf863 Mon Sep 17 00:00:00 2001 From: gramanas Date: Fri, 28 Jan 2022 13:45:30 +0200 Subject: sha1 sum and others --- src/lib.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/lib.c (limited to 'src/lib.c') 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); +} -- cgit v1.2.3