blob: 9eb5395239777d191e065d1020422c7888a14859 (
plain) (
tree)
|
|
#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");
return 0;
}
/* 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);
}
|