mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Use xs_glob() in user_list().
This commit is contained in:
parent
c67bb8d966
commit
53c62db73d
1 changed files with 25 additions and 12 deletions
37
data.c
37
data.c
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue