diff options
author | David Robillard <d@drobilla.net> | 2022-10-02 18:19:49 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 18:49:07 -0500 |
commit | 8c4e3097517e95c8c6ff67f0a972525bfeb3bb1d (patch) | |
tree | 57f574d68cf73add1fa3eda2c1a6551f8b310957 /src/world.c | |
parent | 9c00583bd37522a4f1703bf289587b4546edcf53 (diff) | |
download | serd-8c4e3097517e95c8c6ff67f0a972525bfeb3bb1d.tar.gz serd-8c4e3097517e95c8c6ff67f0a972525bfeb3bb1d.tar.bz2 serd-8c4e3097517e95c8c6ff67f0a972525bfeb3bb1d.zip |
Add serd_world_get_blank()
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/world.c b/src/world.c index c3c3660f..ececd646 100644 --- a/src/world.c +++ b/src/world.c @@ -3,9 +3,12 @@ #include "world.h" +#include "node.h" #include "serd_config.h" #include "system.h" +#include "serd/string_view.h" + #if defined(USE_POSIX_FADVISE) # include <fcntl.h> #endif @@ -14,6 +17,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode) @@ -83,13 +87,43 @@ serd_world_errorf(const SerdWorld* const world, SerdWorld* serd_world_new(void) { - return (SerdWorld*)calloc(1, sizeof(SerdWorld)); + SerdWorld* world = (SerdWorld*)calloc(1, sizeof(SerdWorld)); + SerdNode* blank_node = serd_new_blank(serd_string("b00000000000")); + + if (!world || !blank_node) { + serd_node_free(blank_node); + free(world); + return NULL; + } + + world->blank_node = blank_node; + + return world; } void serd_world_free(SerdWorld* const world) { - free(world); + if (world) { + serd_node_free(world->blank_node); + free(world); + } +} + +const SerdNode* +serd_world_get_blank(SerdWorld* const world) +{ +#define BLANK_CHARS 12 + + char* buf = serd_node_buffer(world->blank_node); + memset(buf, 0, BLANK_CHARS + 1); + + world->blank_node->length = + (size_t)snprintf(buf, BLANK_CHARS + 1, "b%u", ++world->next_blank_id); + + return world->blank_node; + +#undef BLANK_CHARS } void |