summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2024-07-23 09:50:56 +0200
committerGravatar default2024-07-23 09:50:56 +0200
commit5921ec57f6804747c1a678d8ab78262b8235b0ab (patch)
tree39a01a937be2f810a97475ad521bee603a1e9005 /data.c
parentNew functions index_desc_first() and index_desc_next() (unused). (diff)
downloadpenes-snac2-5921ec57f6804747c1a678d8ab78262b8235b0ab.tar.gz
penes-snac2-5921ec57f6804747c1a678d8ab78262b8235b0ab.tar.xz
penes-snac2-5921ec57f6804747c1a678d8ab78262b8235b0ab.zip
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)
651{ 651{
652 xs_list *list = xs_list_new(); 652 xs_list *list = xs_list_new();
653 FILE *f; 653 FILE *f;
654 int n = 0;
655 654
656 if ((f = fopen(fn, "r")) != NULL) { 655 if ((f = fopen(fn, "r")) != NULL) {
657 flock(fileno(f), LOCK_SH); 656 char md5[33];
658 657
659 char line[256]; 658 if (index_desc_first(f, md5, skip)) {
659 int n = 1;
660 660
661 /* move to the end minus one entry (or more, if skipping entries) */ 661 do {
662 if (!fseek(f, 0, SEEK_END) && !fseek(f, (skip + 1) * -33, SEEK_CUR)) { 662 list = xs_list_append(list, md5);
663 while (n < show && fgets(line, sizeof(line), f) != NULL) { 663 } while (n++ < show && index_desc_next(f, md5));
664 if (line[0] != '-') {
665 line[32] = '\0';
666 list = xs_list_append(list, line);
667 n++;
668 }
669
670 /* move backwards 2 entries */
671 if (fseek(f, -66, SEEK_CUR) == -1)
672 break;
673 }
674 } 664 }
675 665
676 fclose(f); 666 fclose(f);