diff options
| author | 2024-07-23 09:34:53 +0200 | |
|---|---|---|
| committer | 2024-07-23 09:34:53 +0200 | |
| commit | 78f383f0251c951ae88a4ce2f266c9e78d9f90af (patch) | |
| tree | f14936b8edb0f5d418e71aa12f39a982bf8c4389 /data.c | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-78f383f0251c951ae88a4ce2f266c9e78d9f90af.tar.gz snac2-78f383f0251c951ae88a4ce2f266c9e78d9f90af.tar.xz snac2-78f383f0251c951ae88a4ce2f266c9e78d9f90af.zip | |
New functions index_desc_first() and index_desc_next() (unused).
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 44 |
1 files changed, 44 insertions, 0 deletions
| @@ -602,6 +602,50 @@ xs_list *index_list(const char *fn, int max) | |||
| 602 | } | 602 | } |
| 603 | 603 | ||
| 604 | 604 | ||
| 605 | int index_desc_next(FILE *f, char md5[33]) | ||
| 606 | /* reads the next entry of a desc index */ | ||
| 607 | { | ||
| 608 | for (;;) { | ||
| 609 | /* move backwards 2 entries */ | ||
| 610 | if (fseek(f, -66, SEEK_CUR) == -1) | ||
| 611 | return 0; | ||
| 612 | |||
| 613 | /* read and md5 */ | ||
| 614 | if (!fread(md5, 33, 1, f)) | ||
| 615 | return 0; | ||
| 616 | |||
| 617 | if (md5[0] != '-') | ||
| 618 | break; | ||
| 619 | } | ||
| 620 | |||
| 621 | md5[32] = '\0'; | ||
| 622 | |||
| 623 | return 1; | ||
| 624 | } | ||
| 625 | |||
| 626 | |||
| 627 | int index_desc_first(FILE *f, char md5[33], int skip) | ||
| 628 | /* reads the first entry of a desc index */ | ||
| 629 | { | ||
| 630 | /* try to position at the end and then back to the first element */ | ||
| 631 | if (fseek(f, 0, SEEK_END) || fseek(f, (skip + 1) * -33, SEEK_CUR)) | ||
| 632 | return 0; | ||
| 633 | |||
| 634 | /* try to read an md5 */ | ||
| 635 | if (!fread(md5, 33, 1, f)) | ||
| 636 | return 0; | ||
| 637 | |||
| 638 | /* null-terminate */ | ||
| 639 | md5[32] = '\0'; | ||
| 640 | |||
| 641 | /* deleted? retry next */ | ||
| 642 | if (md5[0] == '-') | ||
| 643 | return index_desc_next(f, md5); | ||
| 644 | |||
| 645 | return 1; | ||
| 646 | } | ||
| 647 | |||
| 648 | |||
| 605 | xs_list *index_list_desc(const char *fn, int skip, int show) | 649 | xs_list *index_list_desc(const char *fn, int skip, int show) |
| 606 | /* returns an index as a list, in reverse order */ | 650 | /* returns an index as a list, in reverse order */ |
| 607 | { | 651 | { |