diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 41 |
1 files changed, 1 insertions, 40 deletions
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "xs_io.h" | 5 | #include "xs_io.h" |
| 6 | #include "xs_json.h" | 6 | #include "xs_json.h" |
| 7 | #include "xs_openssl.h" | 7 | #include "xs_openssl.h" |
| 8 | #include "xs_glob.h" | ||
| 8 | 9 | ||
| 9 | #include "snac.h" | 10 | #include "snac.h" |
| 10 | 11 | ||
| @@ -144,46 +145,6 @@ int user_open(snac *snac, char *uid) | |||
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | 147 | ||
| 147 | d_char *xs_glob_n(const char *spec, int basename, int reverse, int max) | ||
| 148 | /* does a globbing and returns the found files */ | ||
| 149 | { | ||
| 150 | glob_t globbuf; | ||
| 151 | d_char *list = xs_list_new(); | ||
| 152 | |||
| 153 | if (glob(spec, 0, NULL, &globbuf) == 0) { | ||
| 154 | int n; | ||
| 155 | |||
| 156 | if (max > globbuf.gl_pathc) | ||
| 157 | max = globbuf.gl_pathc; | ||
| 158 | |||
| 159 | for (n = 0; n < max; n++) { | ||
| 160 | char *p; | ||
| 161 | |||
| 162 | if (reverse) | ||
| 163 | p = globbuf.gl_pathv[globbuf.gl_pathc - n - 1]; | ||
| 164 | else | ||
| 165 | p = globbuf.gl_pathv[n]; | ||
| 166 | |||
| 167 | if (p != NULL) { | ||
| 168 | if (basename) { | ||
| 169 | if ((p = strrchr(p, '/')) == NULL) | ||
| 170 | continue; | ||
| 171 | |||
| 172 | p++; | ||
| 173 | } | ||
| 174 | |||
| 175 | list = xs_list_append(list, p); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | globfree(&globbuf); | ||
| 181 | |||
| 182 | return list; | ||
| 183 | } | ||
| 184 | #define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff) | ||
| 185 | |||
| 186 | |||
| 187 | d_char *user_list(void) | 148 | d_char *user_list(void) |
| 188 | /* returns the list of user ids */ | 149 | /* returns the list of user ids */ |
| 189 | { | 150 | { |