snac2

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

commit 78f383f0251c951ae88a4ce2f266c9e78d9f90af
parent ff08f73bc9af80bd07d236992c5fc5b4e9e2a1a2
Author: default <nobody@localhost>
Date:   Tue, 23 Jul 2024 09:34:53 +0200

New functions index_desc_first() and index_desc_next() (unused).

Diffstat:
Mdata.c | 44++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+), 0 deletions(-)

diff --git a/data.c b/data.c @@ -602,6 +602,50 @@ xs_list *index_list(const char *fn, int max) } +int index_desc_next(FILE *f, char md5[33]) +/* reads the next entry of a desc index */ +{ + for (;;) { + /* move backwards 2 entries */ + if (fseek(f, -66, SEEK_CUR) == -1) + return 0; + + /* read and md5 */ + if (!fread(md5, 33, 1, f)) + return 0; + + if (md5[0] != '-') + break; + } + + md5[32] = '\0'; + + return 1; +} + + +int index_desc_first(FILE *f, char md5[33], int skip) +/* reads the first entry of a desc index */ +{ + /* try to position at the end and then back to the first element */ + if (fseek(f, 0, SEEK_END) || fseek(f, (skip + 1) * -33, SEEK_CUR)) + return 0; + + /* try to read an md5 */ + if (!fread(md5, 33, 1, f)) + return 0; + + /* null-terminate */ + md5[32] = '\0'; + + /* deleted? retry next */ + if (md5[0] == '-') + return index_desc_next(f, md5); + + return 1; +} + + xs_list *index_list_desc(const char *fn, int skip, int show) /* returns an index as a list, in reverse order */ {