summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/data.c b/data.c
index 6820537..316dca2 100644
--- a/data.c
+++ b/data.c
@@ -216,7 +216,6 @@ int index_add(const char *fn, const char *id)
216/* adds an id to an index */ 216/* adds an id to an index */
217{ 217{
218 xs *md5 = xs_md5_hex(id, strlen(id)); 218 xs *md5 = xs_md5_hex(id, strlen(id));
219
220 return index_add_md5(fn, md5); 219 return index_add_md5(fn, md5);
221} 220}
222 221
@@ -259,6 +258,39 @@ int index_del(const char *fn, const char *md5)
259} 258}
260 259
261 260
261int index_in_md5(const char *fn, const char *md5)
262/* checks if the md5 is already in the index */
263{
264 FILE *f;
265 int ret = 0;
266
267 if ((f = fopen(fn, "r")) != NULL) {
268 flock(fileno(f), LOCK_SH);
269
270 char line[256];
271
272 while (!ret && fgets(line, sizeof(line), f) != NULL) {
273 line[32] = '\0';
274
275 if (strcmp(line, md5) == 0)
276 ret = 1;
277 }
278
279 fclose(f);
280 }
281
282 return ret;
283}
284
285
286int index_in(const char *fn, const char *id)
287/* checks if the object id is already in the index */
288{
289 xs *md5 = xs_md5_hex(id, strlen(id));
290 return index_in_md5(fn, md5);
291}
292
293
262d_char *index_list(const char *fn, int max) 294d_char *index_list(const char *fn, int max)
263/* returns an index as a list */ 295/* returns an index as a list */
264{ 296{