commit e2789ce
default
·
2023-07-05 12:41:47 +0000 UTC
parent 08e4745
index_list() and index_list_desc() always return a list, even if empty.
1 files changed,
+2,
-4
M
data.c
M
data.c
+2,
-4
1@@ -485,7 +485,7 @@ int index_len(const char *fn)
2 xs_list *index_list(const char *fn, int max)
3 /* returns an index as a list */
4 {
5- xs_list *list = NULL;
6+ xs_list *list = xs_list_new();
7 FILE *f;
8 int n = 0;
9
10@@ -493,7 +493,6 @@ xs_list *index_list(const char *fn, int max)
11 flock(fileno(f), LOCK_SH);
12
13 char line[256];
14- list = xs_list_new();
15
16 while (n < max && fgets(line, sizeof(line), f) != NULL) {
17 if (line[0] != '-') {
18@@ -513,7 +512,7 @@ xs_list *index_list(const char *fn, int max)
19 xs_list *index_list_desc(const char *fn, int skip, int show)
20 /* returns an index as a list, in reverse order */
21 {
22- xs_list *list = NULL;
23+ xs_list *list = xs_list_new();
24 FILE *f;
25 int n = 0;
26
27@@ -521,7 +520,6 @@ xs_list *index_list_desc(const char *fn, int skip, int show)
28 flock(fileno(f), LOCK_SH);
29
30 char line[256];
31- list = xs_list_new();
32
33 /* move to the end minus one entry (or more, if skipping entries) */
34 if (!fseek(f, 0, SEEK_END) && !fseek(f, (skip + 1) * -33, SEEK_CUR)) {