aboutsummaryrefslogtreecommitdiff
path: root/snag/src/util.c
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2026-07-22 17:27:04 -0400
committerJack Jamison <jackqjamison@gmail.com>2026-07-22 17:27:04 -0400
commitf253f5e3d606702688deecea2162f1c5289d277c (patch)
treecc4cdb6bb53a64d0127adbb174556d0e1a2a1cef /snag/src/util.c
parentdfff353cf081024f9e145629dd51ef08526bb54d (diff)
actually download file to correct location
Diffstat (limited to 'snag/src/util.c')
-rw-r--r--snag/src/util.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/snag/src/util.c b/snag/src/util.c
index e79fd34..79c4b17 100644
--- a/snag/src/util.c
+++ b/snag/src/util.c
@@ -78,7 +78,49 @@ char* vastrcat_(int dummy, ...) {
char* output = malloc(len + 1);
if (!output) return NULL;
char* p = output;
+ while ((arg = va_arg(args2, char*))) {
+ size_t alen = strlen(arg);
+ memcpy(p, arg, alen);
+ p += alen;
+ }
+ output[len] = '\0';
+ va_end(args2);
+
+ return output;
+}
+
+char* join_path_(int dummy, ...) {
+
+ va_list args;
+ va_list args2;
+ va_start(args, dummy);
+ va_copy(args2, args);
+
+ // note(jqj): some path joining libraries reset if they encounter an
+ // absolute path, we could implement that easily, but I'm not
+ // sure about it
+
+ // get len of output path
+ size_t len = 0;
+ char* arg = NULL;
+ int i = 0;
while ((arg = va_arg(args, char*))) {
+ if (i > 0) len += 1;
+ len += strlen(arg) + 1;
+ ++i;
+ }
+ va_end(args);
+
+ // allocate and build output
+ char* output = malloc(len + 1);
+ if (!output) return NULL;
+ char* p = output;
+ while ((arg = va_arg(args2, char*))) {
+ if (p != output) {
+ // add slash before every part except the first
+ *p = '/';
+ ++p;
+ }
size_t alen = strlen(arg);
memcpy(p, arg, alen);
p += alen;