Add examples

This commit is contained in:
2025-12-06 01:25:31 +01:00
parent f5b0f3a142
commit bc5679aa11
5 changed files with 97 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <string.h>
#include "../url.h"
int main(void)
{
char base[] = "http://website.com/users/000";
char ref[] = "../images/cat.png";
URL parsed_base;
int ret = url_parse(base, strlen(base), NULL, 1, &parsed_base);
if (ret < 0) {
printf("Couldn't parse base URL\n");
return -1;
}
char dst[1<<10];
ret = url_resolve_reference(ref, strlen(ref), NULL, &parsed_base, 1, dst, (int) sizeof(dst));
if (ret < 0) {
printf("Couldn't resolve reference\n");
return -1;
}
// http://website.com/images/cat.png
printf("%.*s\n", ret, dst);
return 0;
}