diff options
author | default <nobody@localhost> | 2022-10-03 11:08:11 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-10-03 11:08:11 +0200 |
commit | 6f792631bc15b4724efe100cf0c7310cdd6a3aec (patch) | |
tree | 0755624145e37ad28ebdc32cfa2d7d82da8e0b34 /data.c | |
parent | fc346d1e1f7b782d0a65cd8d147f1e8af162056a (diff) |
Use xs_glob() in _timeline_list().
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 40 |
1 files changed, 14 insertions, 26 deletions
@@ -152,12 +152,19 @@ d_char *xs_glob_n(const char *spec, int basename, int reverse, int max) if (glob(spec, 0, NULL, &globbuf) == 0) { int n; - char *p; - if (reverse) { - } - else { - for (n = 0; n < max && (p = globbuf.gl_pathv[n]) != NULL; n++) { + if (max > globbuf.gl_pathc) + max = globbuf.gl_pathc; + + for (n = 0; n < max; n++) { + char *p; + + if (reverse) + p = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; + else + p = globbuf.gl_pathv[n]; + + if (p != NULL) { if (basename) { if ((p = strrchr(p, '/')) == NULL) continue; @@ -379,36 +386,17 @@ d_char *timeline_get(snac *snac, char *fn) d_char *_timeline_list(snac *snac, char *directory, int max) /* returns a list of the timeline filenames */ { - d_char *list; xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, directory); - glob_t globbuf; int c_max; /* maximum number of items in the timeline */ c_max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); + /* never more timeline entries than the configured maximum */ if (max > c_max) max = c_max; - list = xs_list_new(); - - /* get the list in reverse order */ - if (glob(spec, 0, NULL, &globbuf) == 0) { - int n; - - if (max > globbuf.gl_pathc) - max = globbuf.gl_pathc; - - for (n = 0; n < max; n++) { - char *fn = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; - - list = xs_list_append(list, fn); - } - } - - globfree(&globbuf); - - return list; + return xs_glob_n(spec, 0, 1, max); } |