snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 8be8a9282e0c552256ed95eded9364759db80c53
parent 233ba75d1edfde60dd73474dc7f962f00fdd1580
Author: default <nobody@localhost>
Date:   Thu, 24 Nov 2022 13:06:28 +0100

New function index_in().

Diffstat:
Mdata.c | 34+++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/data.c b/data.c @@ -216,7 +216,6 @@ int index_add(const char *fn, const char *id) /* adds an id to an index */ { xs *md5 = xs_md5_hex(id, strlen(id)); - return index_add_md5(fn, md5); } @@ -259,6 +258,39 @@ int index_del(const char *fn, const char *md5) } +int index_in_md5(const char *fn, const char *md5) +/* checks if the md5 is already in the index */ +{ + FILE *f; + int ret = 0; + + if ((f = fopen(fn, "r")) != NULL) { + flock(fileno(f), LOCK_SH); + + char line[256]; + + while (!ret && fgets(line, sizeof(line), f) != NULL) { + line[32] = '\0'; + + if (strcmp(line, md5) == 0) + ret = 1; + } + + fclose(f); + } + + return ret; +} + + +int index_in(const char *fn, const char *id) +/* checks if the object id is already in the index */ +{ + xs *md5 = xs_md5_hex(id, strlen(id)); + return index_in_md5(fn, md5); +} + + d_char *index_list(const char *fn, int max) /* returns an index as a list */ {