From 4120bca8530b87747b44efec0552b946b60d657e Mon Sep 17 00:00:00 2001 From: Rory Bradford Date: Sat, 18 Apr 2020 22:19:52 +0100 Subject: Add wholename option Signed-off-by: Rory Bradford --- ignore.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 ignore.c (limited to 'ignore.c') diff --git a/ignore.c b/ignore.c new file mode 100644 index 0000000..b4cef61 --- /dev/null +++ b/ignore.c @@ -0,0 +1,67 @@ + +#define _POSIX_C_SOURCE 200809L +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include + +#include "ignore.h" + +static int total_size; + +struct ignores *init_ignores(char *path) { + total_size = IGNORE_SIZE; + struct ignores *ignores = calloc(sizeof(struct ignores), 1); + ignores->list = calloc(sizeof(char *), IGNORE_SIZE); + ignores->size = 0; + + int i = 0; + FILE *ignore = fopen(path, "r"); + char *line = NULL; + size_t llen = 0; + ssize_t r; + + if (ignore != NULL) { + while ((r = getline(&line, &llen, ignore)) != -1) { + char *l = calloc(sizeof(char *), strlen(line) - 1); + + for (int j = 0, k = 0; j < strlen(line); j++) { + char c = line[j]; + + if (isspace(c)) { + break; + } + + l[k++] = c; + } + + if (i + 1 > total_size) { + ignores->list = realloc( + ignores->list, sizeof(char *) * (total_size + IGNORE_SIZE)); + total_size += IGNORE_SIZE; + } + + ignores->list[i++] = l; + } + + free(line); + fclose(ignore); + } + + ignores->size = i; + + return ignores; +} + +void free_ignores(struct ignores *ignores) { + if (ignores->size > 0) { + for (int i = 0; i < ignores->size; i++) { + free(ignores->list[i]); + } + } + + free(ignores->list); + free(ignores); +} -- cgit 1.4.1-2-gfad0