summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/collections.c12
-rw-r--r--src/instance.c4
-rw-r--r--src/lilv_internal.h9
-rw-r--r--src/node.c12
-rw-r--r--src/plugin.c40
-rw-r--r--src/pluginclass.c10
-rw-r--r--src/port.c5
-rw-r--r--src/query.c12
-rw-r--r--src/state.c21
-rw-r--r--src/ui.c4
-rw-r--r--src/util.c56
-rw-r--r--src/world.c47
-rw-r--r--src/zix/common.h15
-rw-r--r--src/zix/tree.c5
-rw-r--r--src/zix/tree.h1
15 files changed, 150 insertions, 103 deletions
diff --git a/src/collections.c b/src/collections.c
index 95542da..ebb5633 100644
--- a/src/collections.c
+++ b/src/collections.c
@@ -55,7 +55,7 @@ LilvIter*
lilv_collection_begin(const LilvCollection* collection)
{
if (collection) {
- return zix_tree_begin((LilvCollection*)collection);
+ return (LilvIter*)zix_tree_begin((ZixTree*)collection);
}
return NULL;
}
@@ -104,14 +104,14 @@ const LilvPluginClass*
lilv_plugin_classes_get_by_uri(const LilvPluginClasses* coll,
const LilvNode* uri)
{
- return (LilvPluginClass*)lilv_collection_get_by_uri(coll, uri);
+ return (LilvPluginClass*)lilv_collection_get_by_uri((ZixTree*)coll, uri);
}
LILV_API
const LilvUI*
lilv_uis_get_by_uri(const LilvUIs* coll, const LilvNode* uri)
{
- return (LilvUI*)lilv_collection_get_by_uri((LilvUIs*)coll, uri);
+ return (LilvUI*)lilv_collection_get_by_uri((ZixTree*)coll, uri);
}
/* Plugins */
@@ -126,7 +126,7 @@ LILV_API
const LilvPlugin*
lilv_plugins_get_by_uri(const LilvPlugins* list, const LilvNode* uri)
{
- return (LilvPlugin*)lilv_collection_get_by_uri((LilvPlugins*)list, uri);
+ return (LilvPlugin*)lilv_collection_get_by_uri((ZixTree*)list, uri);
}
/* Nodes */
@@ -166,13 +166,13 @@ prefix##_get(const CT* collection, LilvIter* i) { \
LILV_API \
LilvIter* \
prefix##_next(const CT* collection, LilvIter* i) { \
- return zix_tree_iter_next(i); \
+ return zix_tree_iter_next((ZixTreeIter*)i); \
} \
\
LILV_API \
bool \
prefix##_is_end(const CT* collection, LilvIter* i) { \
- return zix_tree_iter_is_end(i); \
+ return zix_tree_iter_is_end((ZixTreeIter*)i); \
}
LILV_COLLECTION_IMPL(lilv_plugin_classes, LilvPluginClasses, LilvPluginClass)
diff --git a/src/instance.c b/src/instance.c
index 9685a08..0c470e1 100644
--- a/src/instance.c
+++ b/src/instance.c
@@ -33,7 +33,7 @@ lilv_plugin_instantiate(const LilvPlugin* plugin,
const LV2_Feature** local_features = NULL;
if (features == NULL) {
- local_features = malloc(sizeof(LV2_Feature));
+ local_features = (const LV2_Feature**)malloc(sizeof(LV2_Feature));
local_features[0] = NULL;
}
@@ -96,7 +96,7 @@ lilv_plugin_instantiate(const LilvPlugin* plugin,
if (!strcmp((const char*)abs_uri_node.buf,
lilv_node_as_uri(lilv_plugin_get_uri(plugin)))) {
// Create LilvInstance to return
- result = malloc(sizeof(struct LilvInstanceImpl));
+ result = (LilvInstance*)malloc(sizeof(LilvInstance));
result->lv2_descriptor = ld;
result->lv2_handle = ld->instantiate(
ld, sample_rate, (char*)bundle_path,
diff --git a/src/lilv_internal.h b/src/lilv_internal.h
index e4d1a3f..023dbf1 100644
--- a/src/lilv_internal.h
+++ b/src/lilv_internal.h
@@ -21,16 +21,21 @@
extern "C" {
#endif
-#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
+#include <float.h>
#ifdef _WIN32
# include <windows.h>
# define dlopen(path, flags) LoadLibrary(path)
-# define dlclose(lib) FreeLibrary(lib)
+# define dlclose(lib) FreeLibrary((HMODULE)lib)
# define dlsym GetProcAddress
+# ifdef _MSC_VER
+# define __func__ __FUNCTION__
+# define INFINITY DBL_MAX + DBL_MAX
+# define NAN INFINITY - INFINITY
+# endif
static inline char* dlerror(void) { return "Unknown error"; }
#else
# include <dlfcn.h>
diff --git a/src/node.c b/src/node.c
index 169afa1..de35175 100644
--- a/src/node.c
+++ b/src/node.c
@@ -53,7 +53,7 @@ lilv_node_set_numerics_from_string(LilvNode* val, size_t len)
LilvNode*
lilv_node_new(LilvWorld* world, LilvNodeType type, const char* str)
{
- LilvNode* val = malloc(sizeof(struct LilvNodeImpl));
+ LilvNode* val = (LilvNode*)malloc(sizeof(LilvNode));
val->world = world;
val->type = type;
@@ -88,14 +88,14 @@ lilv_node_new_from_node(LilvWorld* world, const SordNode* node)
switch (sord_node_get_type(node)) {
case SORD_URI:
- result = malloc(sizeof(struct LilvNodeImpl));
+ result = (LilvNode*)malloc(sizeof(LilvNode));
result->world = (LilvWorld*)world;
result->type = LILV_VALUE_URI;
result->val.uri_val = sord_node_copy(node);
result->str_val = (char*)sord_node_get_string(result->val.uri_val);
break;
case SORD_BLANK:
- result = malloc(sizeof(struct LilvNodeImpl));
+ result = (LilvNode*)malloc(sizeof(LilvNode));
result->world = (LilvWorld*)world;
result->type = LILV_VALUE_BLANK;
result->val.uri_val = sord_node_copy(node);
@@ -182,7 +182,7 @@ lilv_node_duplicate(const LilvNode* val)
if (val == NULL)
return NULL;
- LilvNode* result = malloc(sizeof(struct LilvNodeImpl));
+ LilvNode* result = (LilvNode*)malloc(sizeof(LilvNode));
result->world = val->world;
result->type = val->type;
@@ -260,12 +260,12 @@ lilv_node_get_turtle_token(const LilvNode* value)
switch (value->type) {
case LILV_VALUE_URI:
len = strlen(value->str_val) + 3;
- result = calloc(len, 1);
+ result = (char*)calloc(len, 1);
snprintf(result, len, "<%s>", value->str_val);
break;
case LILV_VALUE_BLANK:
len = strlen(value->str_val) + 3;
- result = calloc(len, 1);
+ result = (char*)calloc(len, 1);
snprintf(result, len, "_:%s", value->str_val);
break;
case LILV_VALUE_STRING:
diff --git a/src/plugin.c b/src/plugin.c
index ca1723a..5d6a76b 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -33,7 +33,7 @@ LilvPlugin*
lilv_plugin_new(LilvWorld* world, LilvNode* uri, LilvNode* bundle_uri)
{
assert(bundle_uri);
- LilvPlugin* plugin = malloc(sizeof(struct LilvPluginImpl));
+ LilvPlugin* plugin = (LilvPlugin*)malloc(sizeof(LilvPlugin));
plugin->world = world;
plugin->plugin_uri = uri;
plugin->bundle_uri = bundle_uri;
@@ -201,7 +201,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p)
lilv_plugin_load(p);
if (!p->ports) {
- p->ports = malloc(sizeof(LilvPort*));
+ p->ports = (LilvPort**)malloc(sizeof(LilvPort*));
p->ports[0] = NULL;
SordIter* ports = lilv_world_query_internal(
@@ -238,8 +238,8 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p)
if (p->num_ports > this_index) {
this_port = p->ports[this_index];
} else {
- p->ports = realloc(p->ports,
- (this_index + 1) * sizeof(LilvPort*));
+ p->ports = (LilvPort**)realloc(
+ p->ports, (this_index + 1) * sizeof(LilvPort*));
memset(p->ports + p->num_ports, '\0',
(this_index - p->num_ports) * sizeof(LilvPort*));
p->num_ports = this_index + 1;
@@ -260,7 +260,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p)
const SordNode* type = lilv_match_object(types);
if (sord_node_get_type(type) == SORD_URI) {
zix_tree_insert(
- this_port->classes,
+ (ZixTree*)this_port->classes,
lilv_node_new_from_node(p->world, type), NULL);
} else {
LILV_WARNF("Plugin <%s> port type is not a URI\n",
@@ -371,19 +371,19 @@ lilv_plugin_get_class(const LilvPlugin* const_p)
continue;
}
- LilvNode* class = lilv_node_new_from_node(p->world, class_node);
- if (!lilv_node_equals(class, p->world->lv2_plugin_class->uri)) {
+ LilvNode* klass = lilv_node_new_from_node(p->world, class_node);
+ if (!lilv_node_equals(klass, p->world->lv2_plugin_class->uri)) {
const LilvPluginClass* pclass = lilv_plugin_classes_get_by_uri(
- p->world->plugin_classes, class);
+ p->world->plugin_classes, klass);
if (pclass) {
((LilvPlugin*)p)->plugin_class = pclass;
- lilv_node_free(class);
+ lilv_node_free(klass);
break;
}
}
- lilv_node_free(class);
+ lilv_node_free(klass);
}
lilv_match_end(results);
@@ -643,11 +643,13 @@ lilv_plugin_get_supported_features(const LilvPlugin* p)
LilvNodes* result = lilv_nodes_new();
LILV_FOREACH(nodes, i, optional)
- zix_tree_insert(
- result, lilv_node_duplicate(lilv_nodes_get(optional, i)), NULL);
+ zix_tree_insert((ZixTree*)result,
+ lilv_node_duplicate(lilv_nodes_get(optional, i)),
+ NULL);
LILV_FOREACH(nodes, i, required)
- zix_tree_insert(
- result, lilv_node_duplicate(lilv_nodes_get(required, i)), NULL);
+ zix_tree_insert((ZixTree*)result,
+ lilv_node_duplicate(lilv_nodes_get(required, i)),
+ NULL);
lilv_nodes_free(optional);
lilv_nodes_free(required);
@@ -838,7 +840,7 @@ lilv_plugin_get_uis(const LilvPlugin* p)
type,
binary);
- zix_tree_insert(result, lilv_ui, NULL);
+ zix_tree_insert((ZixTree*)result, lilv_ui, NULL);
}
lilv_match_end(uis);
@@ -870,11 +872,11 @@ lilv_plugin_get_related(const LilvPlugin* plugin, const LilvNode* type)
LilvNodes* matches = lilv_nodes_new();
LILV_FOREACH(nodes, i, related) {
- LilvNode* node = lilv_collection_get(related, i);
+ LilvNode* node = (LilvNode*)lilv_collection_get((ZixTree*)related, i);
SordIter* titer = lilv_world_query_internal(
world, node->val.uri_val, world->uris.rdf_a, type->val.uri_val);
if (!sord_iter_end(titer)) {
- zix_tree_insert(matches,
+ zix_tree_insert((ZixTree*)matches,
lilv_node_new_from_node(world, node->val.uri_val),
NULL);
}
@@ -928,7 +930,7 @@ lilv_plugin_write_description(LilvWorld* world,
SerdWriter* writer = serd_writer_new(
SERD_TURTLE,
- SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED,
+ (SerdStyle)(SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
env,
NULL,
serd_file_sink,
@@ -968,7 +970,7 @@ lilv_plugin_write_manifest_entry(LilvWorld* world,
SerdWriter* writer = serd_writer_new(
SERD_TURTLE,
- SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED,
+ (SerdStyle)(SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
env,
NULL,
serd_file_sink,
diff --git a/src/pluginclass.c b/src/pluginclass.c
index 19ba227..46308ab 100644
--- a/src/pluginclass.c
+++ b/src/pluginclass.c
@@ -29,7 +29,7 @@ lilv_plugin_class_new(LilvWorld* world,
if (parent_node && sord_node_get_type(parent_node) != SORD_URI) {
return NULL; // Not an LV2 plugin superclass (FIXME: discover properly)
}
- LilvPluginClass* pc = malloc(sizeof(struct LilvPluginClassImpl));
+ LilvPluginClass* pc = (LilvPluginClass*)malloc(sizeof(LilvPluginClass));
pc->world = world;
pc->uri = lilv_node_new_from_node(world, uri);
pc->label = lilv_node_new(world, LILV_VALUE_STRING, label);
@@ -82,14 +82,14 @@ lilv_plugin_class_get_children(const LilvPluginClass* plugin_class)
LilvPluginClasses* all = plugin_class->world->plugin_classes;
LilvPluginClasses* result = zix_tree_new(false, lilv_ptr_cmp, NULL, NULL);
- for (ZixTreeIter* i = zix_tree_begin(all);
- i != zix_tree_end(all);
+ for (ZixTreeIter* i = zix_tree_begin((ZixTree*)all);
+ i != zix_tree_end((ZixTree*)all);
i = zix_tree_iter_next(i)) {
- const LilvPluginClass* c = zix_tree_get(i);
+ const LilvPluginClass* c = (LilvPluginClass*)zix_tree_get(i);
const LilvNode* parent = lilv_plugin_class_get_parent_uri(c);
if (parent && lilv_node_equals(lilv_plugin_class_get_uri(plugin_class),
parent))
- zix_tree_insert(result, (LilvPluginClass*)c, NULL);
+ zix_tree_insert((ZixTree*)result, (LilvPluginClass*)c, NULL);
}
return result;
diff --git a/src/port.c b/src/port.c
index 037fc97..f008020 100644
--- a/src/port.c
+++ b/src/port.c
@@ -28,7 +28,7 @@ lilv_port_new(LilvWorld* world,
uint32_t index,
const char* symbol)
{
- LilvPort* port = malloc(sizeof(struct LilvPortImpl));
+ LilvPort* port = (LilvPort*)malloc(sizeof(LilvPort));
port->node = sord_node_copy(node);
port->index = index;
port->symbol = lilv_node_new(world, LILV_VALUE_STRING, symbol);
@@ -232,7 +232,8 @@ lilv_port_get_scale_points(const LilvPlugin* p,
p->world->uris.rdfs_label);
if (value && label) {
- zix_tree_insert(ret, lilv_scale_point_new(value, label), NULL);
+ zix_tree_insert(
+ (ZixTree*)ret, lilv_scale_point_new(value, label), NULL);
}
}
lilv_match_end(points);
diff --git a/src/query.c b/src/query.c
index 68c08b4..e09ab1d 100644
--- a/src/query.c
+++ b/src/query.c
@@ -75,14 +75,15 @@ lilv_nodes_from_stream_objects_i18n(LilvWorld* world,
if (lm == LILV_LANG_MATCH_EXACT) {
// Exact language match, add to results
- zix_tree_insert(
- values, lilv_node_new_from_node(world, value), NULL);
+ zix_tree_insert((ZixTree*)values,
+ lilv_node_new_from_node(world, value),
+ NULL);
} else if (lm == LILV_LANG_MATCH_PARTIAL) {
// Partial language match, save in case we find no exact
partial = value;
}
} else {
- zix_tree_insert(values,
+ zix_tree_insert((ZixTree*)values,
lilv_node_new_from_node(world, value),
NULL);
}
@@ -105,7 +106,8 @@ lilv_nodes_from_stream_objects_i18n(LilvWorld* world,
}
if (best) {
- zix_tree_insert(values, lilv_node_new_from_node(world, best), NULL);
+ zix_tree_insert(
+ (ZixTree*)values, lilv_node_new_from_node(world, best), NULL);
} else {
// No matches whatsoever
lilv_nodes_free(values);
@@ -133,7 +135,7 @@ lilv_nodes_from_stream_objects(LilvWorld* world,
: lilv_match_subject(stream);
LilvNode* node = lilv_node_new_from_node(world, value);
if (node) {
- zix_tree_insert(values, node, NULL);
+ zix_tree_insert((ZixTree*)values, node, NULL);
}
}
lilv_match_end(stream);
diff --git a/src/state.c b/src/state.c
index 9f2b738..7bba8c6 100644
--- a/src/state.c
+++ b/src/state.c
@@ -101,8 +101,8 @@ append_port_value(LilvState* state,
const char* port_symbol,
LilvNode* value)
{
- state->values = realloc(state->values,
- (++state->num_values) * sizeof(PortValue));
+ state->values = (PortValue*)realloc(
+ state->values, (++state->num_values) * sizeof(PortValue));
PortValue* pv = &state->values[state->num_values - 1];
pv->symbol = lilv_strdup(port_symbol);
pv->value = value;
@@ -252,7 +252,8 @@ add_feature(const LV2_Feature *const * features, const LV2_Feature* feature)
size_t n_features = 0;
for (; features && features[n_features]; ++n_features) {}
- const LV2_Feature** ret = malloc((n_features + 2) * sizeof(LV2_Feature*));
+ const LV2_Feature** ret = (const LV2_Feature**)malloc(
+ (n_features + 2) * sizeof(LV2_Feature*));
ret[0] = feature;
if (features) {
@@ -275,7 +276,7 @@ lilv_state_new_from_instance(const LilvPlugin* plugin,
{
const LV2_Feature** local_features = NULL;
LilvWorld* const world = plugin->world;
- LilvState* const state = malloc(sizeof(LilvState));
+ LilvState* const state = (LilvState*)malloc(sizeof(LilvState));
memset(state, '\0', sizeof(LilvState));
state->plugin_uri = lilv_node_duplicate(lilv_plugin_get_uri(plugin));
state->abs2rel = zix_tree_new(false, abs_cmp, NULL, path_rel_free);
@@ -429,7 +430,7 @@ new_state_from_model(LilvWorld* world,
const SordNode* node,
const char* dir)
{
- LilvState* const state = malloc(sizeof(LilvState));
+ LilvState* const state = (LilvState*)malloc(sizeof(LilvState));
memset(state, '\0', sizeof(LilvState));
state->dir = dir ? lilv_strdup(dir) : NULL;
@@ -549,7 +550,7 @@ new_state_from_model(LilvWorld* world,
}
if (prop.value) {
- state->props = realloc(
+ state->props = (Property*)realloc(
state->props, (++state->num_props) * sizeof(Property));
state->props[state->num_props - 1] = prop;
}
@@ -704,7 +705,7 @@ open_ttl_writer(FILE* fd, const uint8_t* uri, SerdEnv** new_env)
SerdWriter* writer = serd_writer_new(
SERD_TURTLE,
- SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED,
+ (SerdStyle)(SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED),
env,
&base_uri,
serd_file_sink,
@@ -788,7 +789,7 @@ pathify(const char* in)
{
const size_t in_len = strlen(in);
- char* out = calloc(in_len + 1, 1);
+ char* out = (char*)calloc(in_len + 1, 1);
for (size_t i = 0; i < in_len; ++i) {
char c = in[i];
if (!((c >= 'a' && c <= 'z')
@@ -1078,8 +1079,8 @@ lilv_state_equals(const LilvState* a, const LilvState* b)
}
if (ap->type == a->state_Path) {
- const char* const a_abs = lilv_state_rel2abs(a, ap->value);
- const char* const b_abs = lilv_state_rel2abs(b, bp->value);
+ const char* const a_abs = lilv_state_rel2abs(a, (char*)ap->value);
+ const char* const b_abs = lilv_state_rel2abs(b, (char*)bp->value);
char* const a_real = lilv_realpath(a_abs);
char* const b_real = lilv_realpath(b_abs);
const int cmp = strcmp(a_real, b_real);
diff --git a/src/ui.c b/src/ui.c
index 824ed15..5d2f066 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -30,7 +30,7 @@ lilv_ui_new(LilvWorld* world,
assert(type_uri);
assert(binary_uri);
- LilvUI* ui = malloc(sizeof(struct LilvUIImpl));
+ LilvUI* ui = (LilvUI*)malloc(sizeof(LilvUI));
ui->world = world;
ui->uri = uri;
ui->binary_uri = binary_uri;
@@ -43,7 +43,7 @@ lilv_ui_new(LilvWorld* world,
free(bundle);
ui->classes = lilv_nodes_new();
- zix_tree_insert(ui->classes, type_uri, NULL);
+ zix_tree_insert((ZixTree*)ui->classes, type_uri, NULL);
return ui;
}
diff --git a/src/util.c b/src/util.c
index d52f62a..564b286 100644
--- a/src/util.c
+++ b/src/util.c
@@ -22,15 +22,24 @@
#endif
#include <assert.h>
+#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#include <dirent.h>
+#ifdef _MSC_VER
+# include <direct.h>
+# include <io.h>
+# define F_OK 0
+# define mkdir(path, flags) _mkdir(path)
+#else
+# include <dirent.h>
+# include <unistd.h>
+#endif
+
#include <sys/stat.h>
#include <sys/types.h>
-#include <unistd.h>
#include "lilv_internal.h"
@@ -46,7 +55,7 @@ char*
lilv_strjoin(const char* first, ...)
{
size_t len = strlen(first);
- char* result = malloc(len + 1);
+ char* result = (char*)malloc(len + 1);
memcpy(result, first, len);
@@ -58,7 +67,7 @@ lilv_strjoin(const char* first, ...)
break;
const size_t this_len = strlen(s);
- result = realloc(result, len + this_len + 1);
+ result = (char*)realloc(result, len + this_len + 1);
memcpy(result + len, s, this_len);
len += this_len;
}
@@ -73,7 +82,7 @@ char*
lilv_strdup(const char* str)
{
const size_t len = strlen(str);
- char* dup = malloc(len + 1);
+ char* dup = (char*)malloc(len + 1);
memcpy(dup, str, len + 1);
return dup;
}
@@ -97,7 +106,7 @@ lilv_get_lang(void)
}
const size_t env_lang_len = strlen(env_lang);
- char* const lang = malloc(env_lang_len + 1);
+ char* const lang = (char*)malloc(env_lang_len + 1);
for (size_t i = 0; i < env_lang_len + 1; ++i) {
if (env_lang[i] == '_') {
lang[i] = '-'; // Convert _ to -
@@ -145,9 +154,8 @@ lilv_expand(const char* path)
}
wordfree(&p);
#elif defined(_WIN32)
- static const size_t len = 32767;
- char* ret = malloc(len);
- ExpandEnvironmentStrings(path, ret, len);
+ char* ret = (char*)malloc(MAX_PATH);
+ ExpandEnvironmentStrings(path, ret, MAX_PATH);
#else
char* ret = lilv_strdup(path);
#endif
@@ -165,7 +173,7 @@ lilv_dirname(const char* path)
if (s == path) { // Hit beginning
return (*s == '/') ? lilv_strdup("/") : lilv_strdup(".");
} else { // Pointing to the last character of the result (inclusive)
- char* dirname = malloc(s - path + 2);
+ char* dirname = (char*)malloc(s - path + 2);
memcpy(dirname, path, s - path + 1);
dirname[s - path + 1] = '\0';
return dirname;
@@ -183,7 +191,7 @@ lilv_find_free_path(
const char* in_path, bool (*exists)(const char*, void*), void* user_data)
{
const size_t in_path_len = strlen(in_path);
- char* path = malloc(in_path_len + 7);
+ char* path = (char*)malloc(in_path_len + 7);
memcpy(path, in_path, in_path_len + 1);
for (int i = 2; i < 1000000; ++i) {
@@ -213,7 +221,7 @@ lilv_copy_file(const char* src, const char* dst)
}
static const size_t PAGE_SIZE = 4096;
- char* page = malloc(PAGE_SIZE);
+ char* page = (char*)malloc(PAGE_SIZE);
size_t n_read = 0;
while ((n_read = fread(page, 1, PAGE_SIZE, in)) > 0) {
if (fwrite(page, 1, n_read, out) != n_read) {
@@ -262,7 +270,7 @@ lilv_path_join(const char* a, const char* b)
const size_t a_len = strlen(a);
const size_t b_len = strlen(b);
const size_t pre_len = a_len - (lilv_is_dir_sep(a[a_len - 1]) ? 1 : 0);
- char* path = calloc(1, a_len + b_len + 2);
+ char* path = (char*)calloc(1, a_len + b_len + 2);
memcpy(path, a, pre_len);
path[pre_len] = LILV_DIR_SEP[0];
memcpy(path + pre_len + 1,
@@ -328,13 +336,23 @@ lilv_get_latest_copy(const char* path)
char*
lilv_realpath(const char* path)
{
+#ifdef _WIN32
+ char* out = (char*)malloc(MAX_PATH);
+ GetFullPathName(path, MAX_PATH, out, NULL);
+ return out;
+#else
return realpath(path, NULL);
+#endif
}
int
lilv_symlink(const char* oldpath, const char* newpath)
{
+#ifdef _WIN32
+ return !CreateSymbolicLink(newpath, oldpath, 0);
+#else
return symlink(oldpath, newpath);
+#endif
}
char*
@@ -367,7 +385,7 @@ lilv_path_relative_to(const char* path, const char* base)
// Write up references
const size_t suffix_len = path_len - last_shared_sep;
- char* rel = calloc(1, suffix_len + (up * 3) + 1);
+ char* rel = (char*)calloc(1, suffix_len + (up * 3) + 1);
for (size_t i = 0; i < up; ++i) {
memcpy(rel + (i * 3), ".." LILV_DIR_SEP, 3);
}
@@ -400,6 +418,15 @@ lilv_dir_for_each(const char* path,
void* data,
void (*f)(const char* path, const char* name, void* data))
{
+#ifdef _WIN32
+ char* pat = lilv_path_join(path, "*");
+ WIN32_FIND_DATA fd;
+ HANDLE fh = FindFirstFile(pat, &fd);
+ do {
+ f(path, fd.cFileName, data);
+ } while (FindNextFile(fh, &fd));
+ free(pat);
+#else
DIR* dir = opendir(path);
if (dir) {
struct dirent entry;
@@ -409,6 +436,7 @@ lilv_dir_for_each(const char* path,
}
closedir(dir);
}
+#endif
}
int
diff --git a/src/world.c b/src/world.c
index 48d9515..1811d6f 100644
--- a/src/world.c
+++ b/src/world.c
@@ -25,7 +25,7 @@ LILV_API
LilvWorld*
lilv_world_new(void)
{
- LilvWorld* world = malloc(sizeof(struct LilvWorldImpl));
+ LilvWorld* world = (LilvWorld*)malloc(sizeof(LilvWorld));
world->world = sord_world_new();
if (!world->world)
@@ -124,13 +124,13 @@ lilv_world_free(LilvWorld* world)
const LilvPlugin* p = lilv_plugins_get(world->plugins, i);
lilv_plugin_free((LilvPlugin*)p);
}
- zix_tree_free(world->plugins);
+ zix_tree_free((ZixTree*)world->plugins);
world->plugins = NULL;
- zix_tree_free(world->loaded_files);
+ zix_tree_free((ZixTree*)world->loaded_files);
world->loaded_files = NULL;
- zix_tree_free(world->plugin_classes);
+ zix_tree_free((ZixTree*)world->plugin_classes);
world->plugin_classes = NULL;
sord_free(world->model);
@@ -285,7 +285,7 @@ lilv_world_add_spec(LilvWorld* world,
const SordNode* specification_node,
const SordNode* bundle_node)
{
- LilvSpec* spec = malloc(sizeof(struct LilvSpecImpl));
+ LilvSpec* spec = (LilvSpec*)malloc(sizeof(LilvSpec));
spec->spec = sord_node_copy(specification_node);
spec->bundle = sord_node_copy(bundle_node);
spec->data_uris = lilv_nodes_new();
@@ -299,7 +299,7 @@ lilv_world_add_spec(LilvWorld* world,
NULL);
FOREACH_MATCH(files) {
const SordNode* file_node = lilv_match_object(files);
- zix_tree_insert(spec->data_uris,
+ zix_tree_insert((ZixTree*)spec->data_uris,
lilv_node_new_from_node(world, file_node),
NULL);
}
@@ -335,7 +335,7 @@ lilv_world_add_plugin(LilvWorld* world,
LilvPlugin* plugin = lilv_plugin_new(world, plugin_uri, bundle_uri);
// Add manifest as plugin data file (as if it were rdfs:seeAlso)
- zix_tree_insert(plugin->data_uris,
+ zix_tree_insert((ZixTree*)plugin->data_uris,
lilv_new_uri(world, (const char*)manifest_uri->buf),
NULL);
@@ -356,14 +356,14 @@ lilv_world_add_plugin(LilvWorld* world,
NULL);
FOREACH_MATCH(files) {
const SordNode* file_node = lilv_match_object(files);
- zix_tree_insert(plugin->data_uris,
+ zix_tree_insert((ZixTree*)plugin->data_uris,
lilv_node_new_from_node(world, file_node),
NULL);
}
lilv_match_end(files);
// Add plugin to world plugin sequence
- zix_tree_insert(world->plugins, plugin, NULL);
+ zix_tree_insert((ZixTree*)world->plugins, plugin, NULL);
}
static void
@@ -607,7 +607,7 @@ lilv_world_load_path(LilvWorld* world,
const char* const sep = first_path_sep(lv2_path);
if (sep) {
const size_t dir_len = sep - lv2_path;
- char* const dir = malloc(dir_len + 1);
+ char* const dir = (char*)malloc(dir_len + 1);
memcpy(dir, lv2_path, dir_len);
dir[dir_len] = '\0';
lilv_world_load_directory(world, dir);
@@ -625,15 +625,15 @@ lilv_world_load_specifications(LilvWorld* world)
{
for (LilvSpec* spec = world->specs; spec; spec = spec->next) {
LILV_FOREACH(nodes, f, spec->data_uris) {
- LilvNode* file = lilv_collection_get(spec->data_uris, f);
- const uint8_t* file_uri = (const uint8_t*)lilv_node_as_uri(file);
- SerdEnv* env = serd_env_new(
- sord_node_to_serd_node(file->val.uri_val));
- SerdReader* reader = sord_new_reader(world->model, env,
- SERD_TURTLE, NULL);
+ LilvNode* file = (LilvNode*)lilv_collection_get(spec->data_uris, f);
+
+ const SerdNode* node = sord_node_to_serd_node(file->val.uri_val);
+ SerdEnv* env = serd_env_new(node);
+ SerdReader* reader = sord_new_reader(world->model, env,
+ SERD_TURTLE, NULL);
serd_reader_add_blank_prefix(reader,
lilv_world_blank_node_prefix(world));
- serd_reader_read_file(reader, file_uri);
+ serd_reader_read_file(reader, node->buf);
serd_reader_free(reader);
serd_env_free(env);
}
@@ -701,7 +701,7 @@ lilv_world_load_plugin_classes(LilvWorld* world)
world, parent_node, class_node, (const char*)label);
if (pclass) {
- zix_tree_insert(classes, pclass, NULL);
+ zix_tree_insert((ZixTree*)classes, pclass, NULL);
}
}
lilv_match_end(classes);
@@ -719,15 +719,15 @@ lilv_world_load_all(LilvWorld* world)
lilv_world_load_path(world, lv2_path);
LILV_FOREACH(plugins, p, world->plugins) {
- const LilvPlugin* plugin = lilv_collection_get(world->plugins, p);
- const LilvNode* plugin_uri = lilv_plugin_get_uri(plugin);
+ const LilvPlugin* plugin = (const LilvPlugin*)lilv_collection_get(
+ (ZixTree*)world->plugins, p);
// ?new dc:replaces plugin
SordIter* replacement = lilv_world_find_statements(
world, world->model,
NULL,
world->uris.dc_replaces,
- lilv_node_as_node(plugin_uri),
+ lilv_node_as_node(lilv_plugin_get_uri(plugin)),
NULL);
if (!sord_iter_end(replacement)) {
/* TODO: Check if replacement is actually a known plugin,
@@ -763,7 +763,7 @@ lilv_world_load_resource(LilvWorld* world,
const uint8_t* str = sord_node_get_string(file);
LilvNode* file_node = lilv_node_new_from_node(world, file);
ZixTreeIter* iter;
- if (zix_tree_find(world->loaded_files, file, &iter)) {
+ if (zix_tree_find((ZixTree*)world->loaded_files, file, &iter)) {
if (sord_node_get_type(file) == SORD_URI) {
const SerdNode* base = sord_node_to_serd_node(file);
SerdEnv* env = serd_env_new(base);
@@ -771,7 +771,8 @@ lilv_world_load_resource(LilvWorld* world,
world->model, env, SERD_TURTLE, (SordNode*)file);
if (!serd_reader_read_file(reader, str)) {
++n_read;
- zix_tree_insert(world->loaded_files, file_node, NULL);
+ zix_tree_insert(
+ (ZixTree*)world->loaded_files, file_node, NULL);
file_node = NULL; // prevent deletion...
} else {
LILV_ERRORF("Error loading resource `%s'\n", str);
diff --git a/src/zix/common.h b/src/zix/common.h
index 59a9511..ab7e431 100644
--- a/src/zix/common.h
+++ b/src/zix/common.h
@@ -17,8 +17,6 @@
#ifndef ZIX_COMMON_H
#define ZIX_COMMON_H
-#include <stdbool.h>
-
/**
@addtogroup zix
@{
@@ -43,6 +41,12 @@
#endif
/** @endcond */
+#ifdef __cplusplus
+extern "C" {
+#else
+# include <stdbool.h>
+#endif
+
typedef enum {
ZIX_STATUS_SUCCESS,
ZIX_STATUS_ERROR,
@@ -66,7 +70,12 @@ typedef bool (*ZixEqualFunc)(const void* a, const void* b);
*/
typedef void (*ZixDestroyFunc)(void* ptr);
-/**@}
+/**
+ @}
*/
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* ZIX_COMMON_H */
diff --git a/src/zix/tree.c b/src/zix/tree.c
index d22f438..39f3b36 100644
--- a/src/zix/tree.c
+++ b/src/zix/tree.c
@@ -15,7 +15,6 @@
*/
#include <assert.h>
-#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -74,7 +73,7 @@ zix_tree_new(bool allow_duplicates,
void* cmp_data,
ZixDestroyFunc destroy)
{
- ZixTree* t = malloc(sizeof(ZixTree));
+ ZixTree* t = (ZixTree*)malloc(sizeof(ZixTree));
t->root = NULL;
t->destroy = destroy;
t->cmp = cmp;
@@ -368,7 +367,7 @@ zix_tree_insert(ZixTree* t, void* e, ZixTreeIter** ti)
}
// Allocate a new node n
- if (!(n = malloc(sizeof(ZixTreeNode)))) {
+ if (!(n = (ZixTreeNode*)malloc(sizeof(ZixTreeNode)))) {
return ZIX_STATUS_NO_MEM;
}
memset(n, '\0', sizeof(ZixTreeNode));
diff --git a/src/zix/tree.h b/src/zix/tree.h
index 378db28..5a74fd7 100644
--- a/src/zix/tree.h
+++ b/src/zix/tree.h
@@ -17,7 +17,6 @@
#ifndef ZIX_TREE_H
#define ZIX_TREE_H
-#include <stdbool.h>
#include <stddef.h>
#include "zix/common.h"