summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-07-23 09:50:56 +0200
committerdefault <nobody@localhost>2024-07-23 09:50:56 +0200
commit5921ec57f6804747c1a678d8ab78262b8235b0ab (patch)
tree39a01a937be2f810a97475ad521bee603a1e9005 /data.c
parent78f383f0251c951ae88a4ce2f266c9e78d9f90af (diff)
Reimplemented index_list_desc() by way of index_desc_first() and index_desc_next().
Diffstat (limited to 'data.c')
-rw-r--r--data.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/data.c b/data.c
index 9bf82e1..7f0feef 100644
--- a/data.c
+++ b/data.c
@@ -651,26 +651,16 @@ xs_list *index_list_desc(const char *fn, int skip, int show)
{
xs_list *list = xs_list_new();
FILE *f;
- int n = 0;
if ((f = fopen(fn, "r")) != NULL) {
- flock(fileno(f), LOCK_SH);
+ char md5[33];
- char line[256];
+ if (index_desc_first(f, md5, skip)) {
+ int n = 1;
- /* move to the end minus one entry (or more, if skipping entries) */
- if (!fseek(f, 0, SEEK_END) && !fseek(f, (skip + 1) * -33, SEEK_CUR)) {
- while (n < show && fgets(line, sizeof(line), f) != NULL) {
- if (line[0] != '-') {
- line[32] = '\0';
- list = xs_list_append(list, line);
- n++;
- }
-
- /* move backwards 2 entries */
- if (fseek(f, -66, SEEK_CUR) == -1)
- break;
- }
+ do {
+ list = xs_list_append(list, md5);
+ } while (n++ < show && index_desc_next(f, md5));
}
fclose(f);