diff options
author | David Robillard <d@drobilla.net> | 2021-08-02 11:56:54 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:08 -0500 |
commit | d206d6020c23420078a8b2579f0274723b1b470a (patch) | |
tree | 2883efcdf9c17fa42d18862d565e4d9d6a3e6f7e /tools/console.c | |
parent | 4e1850852a74fe6904beabf793ea8d9915cab246 (diff) | |
download | serd-d206d6020c23420078a8b2579f0274723b1b470a.tar.gz serd-d206d6020c23420078a8b2579f0274723b1b470a.tar.bz2 serd-d206d6020c23420078a8b2579f0274723b1b470a.zip |
Factor out setting base URI from a path
Diffstat (limited to 'tools/console.c')
-rw-r--r-- | tools/console.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/console.c b/tools/console.c index f6a15ecb..c187f500 100644 --- a/tools/console.c +++ b/tools/console.c @@ -4,6 +4,8 @@ #include "console.h" #include "serd/serd.h" +#include "zix/allocator.h" +#include "zix/filesystem.h" #ifdef _WIN32 # ifdef _MSC_VER @@ -43,6 +45,24 @@ serd_print_version(const char* const program) return 0; } +SerdStatus +serd_set_base_uri_from_path(SerdEnv* const env, const char* const path) +{ + char* const input_path = zix_canonical_path(NULL, path); + if (!input_path) { + return SERD_BAD_ARG; + } + + SerdNode* const file_uri = + serd_new_file_uri(serd_string(input_path), serd_empty_string()); + + serd_env_set_base_uri(env, serd_node_string_view(file_uri)); + serd_node_free(file_uri); + zix_free(NULL, input_path); + + return SERD_SUCCESS; +} + /// Wrapper for getc that is compatible with SerdReadFunc but faster than fread static size_t serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream) |