Use xs_glob() in user_list().

This commit is contained in:
default 2022-10-03 10:51:52 +02:00
parent c67bb8d966
commit 53c62db73d

37
data.c
View file

@ -144,25 +144,29 @@ int user_open(snac *snac, char *uid)
} }
d_char *user_list(void) d_char *xs_glob_n(const char *spec, int basename, int reverse, int max)
/* returns the list of user ids */ /* does a globbing and returns the found files */
{ {
d_char *list;
xs *spec;
glob_t globbuf; glob_t globbuf;
d_char *list = xs_list_new();
globbuf.gl_offs = 1;
list = xs_list_new();
spec = xs_fmt("%s/user/" "*", srv_basedir);
if (glob(spec, 0, NULL, &globbuf) == 0) { if (glob(spec, 0, NULL, &globbuf) == 0) {
int n; int n;
char *p; char *p;
for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) { if (reverse) {
if ((p = strrchr(p, '/')) != NULL) }
list = xs_list_append(list, p + 1); else {
for (n = 0; n < max && (p = globbuf.gl_pathv[n]) != NULL; n++) {
if (basename) {
if ((p = strrchr(p, '/')) == NULL)
continue;
p++;
}
list = xs_list_append(list, p);
}
} }
} }
@ -170,6 +174,15 @@ d_char *user_list(void)
return list; return list;
} }
#define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff)
d_char *user_list(void)
/* returns the list of user ids */
{
xs *spec = xs_fmt("%s/user/" "*", srv_basedir);
return xs_glob(spec, 1, 0);
}
double mtime(char *fn) double mtime(char *fn)