mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 06:25:04 +00:00
Backport from xs.
This commit is contained in:
parent
7414b000ee
commit
e8c421c51d
4 changed files with 62 additions and 43 deletions
7
Makefile
7
Makefile
|
@ -16,14 +16,15 @@ dep:
|
|||
|
||||
activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h \
|
||||
xs_mime.h xs_openssl.h xs_regex.h xs_time.h snac.h
|
||||
data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h
|
||||
data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h xs_glob.h snac.h
|
||||
html.o: html.c xs.h xs_io.h xs_encdec.h xs_json.h xs_regex.h xs_set.h \
|
||||
xs_openssl.h snac.h
|
||||
xs_openssl.h xs_time.h snac.h
|
||||
http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h xs_time.h \
|
||||
snac.h
|
||||
httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \
|
||||
xs_httpd.h snac.h
|
||||
main.o: main.c xs.h xs_io.h xs_encdec.h xs_json.h snac.h
|
||||
snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h xs_openssl.h \
|
||||
xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h snac.h
|
||||
xs_socket.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h \
|
||||
snac.h
|
||||
webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h
|
||||
|
|
41
data.c
41
data.c
|
@ -5,6 +5,7 @@
|
|||
#include "xs_io.h"
|
||||
#include "xs_json.h"
|
||||
#include "xs_openssl.h"
|
||||
#include "xs_glob.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
@ -144,46 +145,6 @@ int user_open(snac *snac, char *uid)
|
|||
}
|
||||
|
||||
|
||||
d_char *xs_glob_n(const char *spec, int basename, int reverse, int max)
|
||||
/* does a globbing and returns the found files */
|
||||
{
|
||||
glob_t globbuf;
|
||||
d_char *list = xs_list_new();
|
||||
|
||||
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 *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;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
list = xs_list_append(list, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
globfree(&globbuf);
|
||||
|
||||
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 */
|
||||
{
|
||||
|
|
1
snac.c
1
snac.c
|
@ -15,6 +15,7 @@
|
|||
#include "xs_regex.h"
|
||||
#include "xs_set.h"
|
||||
#include "xs_time.h"
|
||||
#include "xs_glob.h"
|
||||
|
||||
#include "snac.h"
|
||||
|
||||
|
|
56
xs_glob.h
Normal file
56
xs_glob.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* copyright (c) 2022 grunfink - MIT license */
|
||||
|
||||
#ifndef _XS_GLOB_H
|
||||
|
||||
#define _XS_GLOB_H
|
||||
|
||||
d_char *xs_glob_n(const char *spec, int basename, int reverse, int max);
|
||||
#define xs_glob(spec, basename, reverse) xs_glob_n(spec, basename, reverse, 0xfffffff)
|
||||
|
||||
|
||||
#ifdef XS_IMPLEMENTATION
|
||||
|
||||
#include <glob.h>
|
||||
|
||||
d_char *xs_glob_n(const char *spec, int basename, int reverse, int max)
|
||||
/* does a globbing and returns the found files */
|
||||
{
|
||||
glob_t globbuf;
|
||||
d_char *list = xs_list_new();
|
||||
|
||||
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 *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;
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
list = xs_list_append(list, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
globfree(&globbuf);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
#endif /* XS_IMPLEMENTATION */
|
||||
|
||||
#endif /* _XS_GLOB_H */
|
Loading…
Reference in a new issue