From 4f261ec7b949b89146b699d04bd9e79ce87f7f10 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 26 Nov 2022 17:35:18 +0100 Subject: [PATCH] New function index_first(). --- data.c | 19 +++++++++++++++++++ snac.h | 1 + 2 files changed, 20 insertions(+) diff --git a/data.c b/data.c index 5f5e8c1..4a05f1b 100644 --- a/data.c +++ b/data.c @@ -306,6 +306,25 @@ int index_in(const char *fn, const char *id) } +int index_first(const char *fn, char *line, int size) +/* reads the first entry of an index */ +{ + FILE *f; + int ret = 0; + + if ((f = fopen(fn, "r")) != NULL) { + if (fgets(line, size, f) != NULL) { + line[32] = '\0'; + ret = 1; + } + + fclose(f); + } + + return ret; +} + + d_char *index_list(const char *fn, int max) /* returns an index as a list */ { diff --git a/snac.h b/snac.h index a9c8606..5323a2a 100644 --- a/snac.h +++ b/snac.h @@ -55,6 +55,7 @@ double mtime_nl(const char *fn, int *n_link); int index_add(const char *fn, const char *md5); int index_del(const char *fn, const char *md5); +int index_first(const char *fn, char *buf, int size); d_char *index_list(const char *fn, int max); d_char *index_list_desc(const char *fn, int max);