-
Notifications
You must be signed in to change notification settings - Fork 6
/
ignore.c
51 lines (47 loc) · 899 Bytes
/
ignore.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (C) Johan Malm 2024 */
#define _POSIX_C_SOURCE 200809L
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include "ignore.h"
static GList *ignore_files;
void
ignore_init(const char *filename)
{
if (!filename || !*filename) {
return;
}
FILE *stream = fopen(filename, "r");
if (!stream) {
return;
}
char *line = NULL;
size_t len = 0;
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');
if (p) {
*p = '\0';
}
ignore_files = g_list_append(ignore_files,
g_strdup(g_strstrip(line)));
}
free(line);
fclose(stream);
}
void
ignore_finish(void)
{
g_list_free_full(ignore_files, g_free);
}
bool
should_ignore(const char *filename)
{
GList *iter;
for (iter = ignore_files; iter; iter = iter->next) {
if (!g_strcmp0((char *)iter->data, filename)) {
return true;
}
}
return false;
}