diff options
| -rw-r--r-- | data.c | 22 | ||||
| -rw-r--r-- | snac.h | 2 |
2 files changed, 8 insertions, 16 deletions
| @@ -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); |
| @@ -101,6 +101,8 @@ int index_gc(const char *fn); | |||
| 101 | int index_first(const char *fn, char *buf, int size); | 101 | int index_first(const char *fn, char *buf, int size); |
| 102 | int index_len(const char *fn); | 102 | int index_len(const char *fn); |
| 103 | xs_list *index_list(const char *fn, int max); | 103 | xs_list *index_list(const char *fn, int max); |
| 104 | int index_desc_next(FILE *f, char md5[33]); | ||
| 105 | int index_desc_first(FILE *f, char md5[33], int skip); | ||
| 104 | xs_list *index_list_desc(const char *fn, int skip, int show); | 106 | xs_list *index_list_desc(const char *fn, int skip, int show); |
| 105 | 107 | ||
| 106 | int object_add(const char *id, const xs_dict *obj); | 108 | int object_add(const char *id, const xs_dict *obj); |