aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uri.c')
-rw-r--r--src/uri.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/uri.c b/src/uri.c
index 6fc1f17c..234bf834 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -1,10 +1,12 @@
// Copyright 2011-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
+#include "memory.h"
#include "string_utils.h"
#include "uri_utils.h"
#include "serd/buffer.h"
+#include "serd/memory.h"
#include "serd/status.h"
#include "serd/stream.h"
#include "serd/string_view.h"
@@ -14,7 +16,6 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
static SerdStatus
@@ -25,7 +26,9 @@ write_file_uri_char(const char c, void* const stream)
}
static char*
-parse_hostname(const char* const authority, char** const hostname)
+parse_hostname(SerdAllocator* const allocator,
+ const char* const authority,
+ char** const hostname)
{
char* const path = strchr(authority, '/');
if (!path) {
@@ -34,7 +37,7 @@ parse_hostname(const char* const authority, char** const hostname)
if (hostname) {
const size_t len = (size_t)(path - authority);
- if (!(*hostname = (char*)calloc(len + 1, 1))) {
+ if (!(*hostname = (char*)serd_acalloc(allocator, len + 1, 1))) {
return NULL;
}
@@ -45,7 +48,9 @@ parse_hostname(const char* const authority, char** const hostname)
}
char*
-serd_parse_file_uri(const char* const uri, char** const hostname)
+serd_parse_file_uri(SerdAllocator* const allocator,
+ const char* const uri,
+ char** const hostname)
{
assert(uri);
@@ -60,7 +65,7 @@ serd_parse_file_uri(const char* const uri, char** const hostname)
const char* auth = uri + 7;
if (*auth == '/') { // No hostname
path = auth;
- } else if (!(path = parse_hostname(auth, hostname))) {
+ } else if (!(path = parse_hostname(allocator, auth, hostname))) {
return NULL;
}
}
@@ -69,7 +74,7 @@ serd_parse_file_uri(const char* const uri, char** const hostname)
++path;
}
- SerdBuffer buffer = {NULL, 0};
+ SerdBuffer buffer = {allocator, NULL, 0};
for (const char* s = path; !st && *s; ++s) {
if (*s != '%') {
st = write_file_uri_char(*s, &buffer);
@@ -90,7 +95,7 @@ serd_parse_file_uri(const char* const uri, char** const hostname)
}
if (st || serd_buffer_close(&buffer)) {
- free(buffer.buf);
+ serd_free(allocator, buffer.buf);
return NULL;
}