mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 11:40:27 +03:00
New function index_in().
This commit is contained in:
parent
233ba75d1e
commit
8be8a9282e
34
data.c
34
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 */
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user