diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 37 |
1 files changed, 25 insertions, 12 deletions
| @@ -144,25 +144,29 @@ int user_open(snac *snac, char *uid) | |||
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | d_char *user_list(void) | 147 | d_char *xs_glob_n(const char *spec, int basename, int reverse, int max) |
| 148 | /* returns the list of user ids */ | 148 | /* does a globbing and returns the found files */ |
| 149 | { | 149 | { |
| 150 | d_char *list; | ||
| 151 | xs *spec; | ||
| 152 | glob_t globbuf; | 150 | glob_t globbuf; |
| 153 | 151 | d_char *list = xs_list_new(); | |
| 154 | globbuf.gl_offs = 1; | ||
| 155 | |||
| 156 | list = xs_list_new(); | ||
| 157 | spec = xs_fmt("%s/user/" "*", srv_basedir); | ||
| 158 | 152 | ||
| 159 | if (glob(spec, 0, NULL, &globbuf) == 0) { | 153 | if (glob(spec, 0, NULL, &globbuf) == 0) { |
| 160 | int n; | 154 | int n; |
| 161 | char *p; | 155 | char *p; |
| 162 | 156 | ||
| 163 | for (n = 0; (p = globbuf.gl_pathv[n]) != NULL; n++) { | 157 | if (reverse) { |
| 164 | if ((p = strrchr(p, '/')) != NULL) | 158 | } |
| 165 | list = xs_list_append(list, p + 1); | 159 | else { |
| 160 | for (n = 0; n < max && (p = globbuf.gl_pathv[n]) != NULL; n++) { | ||
| 161 | if (basename) { | ||
| 162 | if ((p = strrchr(p, '/')) == NULL) | ||
| 163 | continue; | ||
| 164 | |||
| 165 | p++; | ||
| 166 | } | ||
| 167 | |||
| 168 | list = xs_list_append(list, p); | ||
| 169 | } | ||
| 166 | } | 170 | } |
| 167 | } | 171 | } |
| 168 | 172 | ||
| @@ -170,6 +174,15 @@ d_char *user_list(void) | |||
| 170 | 174 | ||
| 171 | return list; | 175 | return list; |
| 172 | } | 176 | } |
| 177 | #define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff) | ||
| 178 | |||
| 179 | |||
| 180 | d_char *user_list(void) | ||
| 181 | /* returns the list of user ids */ | ||
| 182 | { | ||
| 183 | xs *spec = xs_fmt("%s/user/" "*", srv_basedir); | ||
| 184 | return xs_glob(spec, 1, 0); | ||
| 185 | } | ||
| 173 | 186 | ||
| 174 | 187 | ||
| 175 | double mtime(char *fn) | 188 | double mtime(char *fn) |