summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c22
-rw-r--r--snac.h2
2 files changed, 8 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);
diff --git a/snac.h b/snac.h
index 9dd2024..0923df0 100644
--- a/snac.h
+++ b/snac.h
@@ -101,6 +101,8 @@ int index_gc(const char *fn);
101int index_first(const char *fn, char *buf, int size); 101int index_first(const char *fn, char *buf, int size);
102int index_len(const char *fn); 102int index_len(const char *fn);
103xs_list *index_list(const char *fn, int max); 103xs_list *index_list(const char *fn, int max);
104int index_desc_next(FILE *f, char md5[33]);
105int index_desc_first(FILE *f, char md5[33], int skip);
104xs_list *index_list_desc(const char *fn, int skip, int show); 106xs_list *index_list_desc(const char *fn, int skip, int show);
105 107
106int object_add(const char *id, const xs_dict *obj); 108int object_add(const char *id, const xs_dict *obj);