summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-07-23 09:34:53 +0200
committerdefault <nobody@localhost>2024-07-23 09:34:53 +0200
commit78f383f0251c951ae88a4ce2f266c9e78d9f90af (patch)
treef14936b8edb0f5d418e71aa12f39a982bf8c4389 /data.c
parentff08f73bc9af80bd07d236992c5fc5b4e9e2a1a2 (diff)
New functions index_desc_first() and index_desc_next() (unused).
Diffstat (limited to 'data.c')
-rw-r--r--data.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/data.c b/data.c
index 2a92e28..9bf82e1 100644
--- 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 */
{