commit 78f383f

default  ·  2024-07-23 07:34:53 +0000 UTC
parent ff08f73
New functions index_desc_first() and index_desc_next() (unused).
1 files changed,  +44, -0
M data.c
M data.c
+44, -0
 1@@ -602,6 +602,50 @@ xs_list *index_list(const char *fn, int max)
 2 }
 3 
 4 
 5+int index_desc_next(FILE *f, char md5[33])
 6+/* reads the next entry of a desc index */
 7+{
 8+    for (;;) {
 9+        /* move backwards 2 entries */
10+        if (fseek(f, -66, SEEK_CUR) == -1)
11+            return 0;
12+
13+        /* read and md5 */
14+        if (!fread(md5, 33, 1, f))
15+            return 0;
16+
17+        if (md5[0] != '-')
18+            break;
19+    }
20+
21+    md5[32] = '\0';
22+
23+    return 1;
24+}
25+
26+
27+int index_desc_first(FILE *f, char md5[33], int skip)
28+/* reads the first entry of a desc index */
29+{
30+    /* try to position at the end and then back to the first element */
31+    if (fseek(f, 0, SEEK_END) || fseek(f, (skip + 1) * -33, SEEK_CUR))
32+        return 0;
33+
34+    /* try to read an md5 */
35+    if (!fread(md5, 33, 1, f))
36+        return 0;
37+
38+    /* null-terminate */
39+    md5[32] = '\0';
40+
41+    /* deleted? retry next */
42+    if (md5[0] == '-')
43+        return index_desc_next(f, md5);
44+
45+    return 1;
46+}
47+
48+
49 xs_list *index_list_desc(const char *fn, int skip, int show)
50 /* returns an index as a list, in reverse order */
51 {