diff options
author | David Robillard <d@drobilla.net> | 2011-03-28 03:13:05 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-03-28 03:13:05 +0000 |
commit | 7b067fc094b0495359557e6442636a38567e995c (patch) | |
tree | fb78b8bf472aa0196dd7f9e2ed7ac74d2e976df2 /src | |
parent | db78a2f56fc8bd3b188ea54e0461cb3108c2dedb (diff) | |
download | lilv-7b067fc094b0495359557e6442636a38567e995c.tar.gz lilv-7b067fc094b0495359557e6442636a38567e995c.tar.bz2 lilv-7b067fc094b0495359557e6442636a38567e995c.zip |
Fix Windows build
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3129 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin.c | 4 | ||||
-rw-r--r-- | src/pluginui.c | 2 | ||||
-rw-r--r-- | src/slv2_internal.h | 9 | ||||
-rw-r--r-- | src/util.c | 19 | ||||
-rw-r--r-- | src/value.c | 14 | ||||
-rw-r--r-- | src/world.c | 63 |
6 files changed, 83 insertions, 28 deletions
diff --git a/src/plugin.c b/src/plugin.c index ce5299e..a4f9338 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -30,10 +30,6 @@ #include <stdlib.h> #include <string.h> -#ifdef SLV2_DYN_MANIFEST -#include <dlfcn.h> -#endif - #include "slv2-config.h" #include "slv2_internal.h" diff --git a/src/pluginui.c b/src/pluginui.c index 4d61690..c81a5dd 100644 --- a/src/pluginui.c +++ b/src/pluginui.c @@ -51,7 +51,7 @@ slv2_ui_new(SLV2World world, ui->binary_uri = binary_uri; // FIXME: kludge - char* bundle = strdup(slv2_value_as_string(ui->binary_uri)); + char* bundle = slv2_strdup(slv2_value_as_string(ui->binary_uri)); char* last_slash = strrchr(bundle, '/') + 1; *last_slash = '\0'; ui->bundle_uri = slv2_value_new_uri(world, bundle); diff --git a/src/slv2_internal.h b/src/slv2_internal.h index d24d570..e2a6807 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -28,7 +28,15 @@ extern "C" { #include <stdint.h> #include <stdlib.h> +#ifdef __WIN32__ +#include <windows.h> +#define dlopen(path, flags) LoadLibrary(path) +#define dlclose(lib) FreeLibrary(lib) +#define dlsym GetProcAddress +static inline char* dlerror(void) { return "Unknown error"; } +#else #include <dlfcn.h> +#endif #include <glib.h> @@ -379,6 +387,7 @@ SLV2Values slv2_values_from_stream_objects(SLV2Plugin p, /* ********* Utilities ********* */ char* slv2_strjoin(const char* first, ...); +char* slv2_strdup(const char* str); char* slv2_get_lang(); uint8_t* slv2_qname_expand(SLV2Plugin p, const char* qname); @@ -59,13 +59,28 @@ slv2_strjoin(const char* first, ...) return result; } +char* +slv2_strdup(const char* str) +{ + const size_t len = strlen(str); + char* dup = malloc(len + 1); + memcpy(dup, str, len + 1); + return dup; +} + const char* slv2_uri_to_path(const char* uri) { - if (!strncmp(uri, "file://", (size_t)7)) +#ifdef __WIN32__ + if (!strncmp(uri, "file:///", (size_t)8)) { + return (char*)(uri + 8); +#else + if (!strncmp(uri, "file://", (size_t)7)) { return (char*)(uri + 7); - else +#endif + } else { return NULL; + } } /** Return the current LANG converted to Turtle (i.e. RFC3066) style. diff --git a/src/value.c b/src/value.c index 09a0720..3dce427 100644 --- a/src/value.c +++ b/src/value.c @@ -48,7 +48,7 @@ slv2_value_set_numerics_from_string(SLV2Value val) break; case SLV2_VALUE_INT: // FIXME: locale kludge, need a locale independent strtol - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); val->val.int_val = strtol(val->str_val, &endptr, 10); setlocale(LC_NUMERIC, locale); @@ -56,7 +56,7 @@ slv2_value_set_numerics_from_string(SLV2Value val) break; case SLV2_VALUE_FLOAT: // FIXME: locale kludge, need a locale independent strtod - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); val->val.float_val = strtod(val->str_val, &endptr); setlocale(LC_NUMERIC, locale); @@ -91,7 +91,7 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) case SLV2_VALUE_INT: case SLV2_VALUE_FLOAT: case SLV2_VALUE_BOOL: - val->str_val = strdup(str); + val->str_val = slv2_strdup(str); break; } @@ -207,7 +207,7 @@ slv2_value_duplicate(SLV2Value val) result->val.uri_val = slv2_node_copy(val->val.uri_val); result->str_val = (char*)sord_node_get_string(result->val.uri_val); } else { - result->str_val = strdup(val->str_val); + result->str_val = slv2_strdup(val->str_val); result->val = val->val; } @@ -277,12 +277,12 @@ slv2_value_get_turtle_token(SLV2Value value) case SLV2_VALUE_STRING: case SLV2_VALUE_QNAME_UNUSED: case SLV2_VALUE_BOOL: - result = strdup(value->str_val); + result = slv2_strdup(value->str_val); break; case SLV2_VALUE_INT: // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign // FIXME: locale kludge, need a locale independent snprintf - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); len = 20; result = calloc(len, 1); setlocale(LC_NUMERIC, "POSIX"); @@ -291,7 +291,7 @@ slv2_value_get_turtle_token(SLV2Value value) break; case SLV2_VALUE_FLOAT: // FIXME: locale kludge, need a locale independent snprintf - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); len = 20; // FIXME: proper maximum value? result = calloc(len, 1); setlocale(LC_NUMERIC, "POSIX"); diff --git a/src/world.c b/src/world.c index 6209c8c..ea2e20c 100644 --- a/src/world.c +++ b/src/world.c @@ -30,9 +30,8 @@ #include <string.h> #include <dirent.h> +#ifdef HAVE_WORDEXP #include <wordexp.h> -#ifdef SLV2_DYN_MANIFEST -#include <dlfcn.h> #endif #include "slv2_internal.h" @@ -212,7 +211,8 @@ slv2_world_find_statements(SLV2World world, } static SerdNode -slv2_new_uri_relative_to_base(const uint8_t* uri_str, const uint8_t* base_uri_str) +slv2_new_uri_relative_to_base(const uint8_t* uri_str, + const uint8_t* base_uri_str) { SerdURI base_uri; if (!serd_uri_parse(base_uri_str, &base_uri)) { @@ -496,22 +496,26 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri) static char* expand(const char* path) { +#ifdef HAVE_WORDEXP char* ret = NULL; wordexp_t p; wordexp(path, &p, 0); if (p.we_wordc == 0) { - // Literal directory path (e.g. no variables or ~) - ret = strdup(path); + /* Literal directory path (e.g. no variables or ~) */ + ret = slv2_strdup(path); } else if (p.we_wordc == 1) { - // Directory path expands (e.g. contains ~ or $FOO) - ret = strdup(p.we_wordv[0]); + /* Directory path expands (e.g. contains ~ or $FOO) */ + ret = slv2_strdup(p.we_wordv[0]); } else { - // Multiple expansions in a single directory path? - fprintf(stderr, "lv2config: malformed path `%s' ignored\n", path); + /* Multiple expansions in a single directory path? */ + SLV2_ERRORF("malformed path `%s' ignored\n", path); } wordfree(&p); +#else + char* ret = slv2_strdup(path); +#endif return ret; } @@ -521,31 +525,43 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) { char* path = expand(dir_path); if (!path) { + SLV2_WARNF("empty path `%s'\n", path); return; } DIR* pdir = opendir(path); if (!pdir) { + SLV2_WARNF("failed to open directory `%s' (%s)\n", + path, strerror(errno)); free(path); return; } +#ifdef __WIN32__ + static const char* const file_scheme = "file:///"; +#else + static const char* const file_scheme = "file://"; +#endif + const size_t file_scheme_len = strlen(file_scheme); + struct dirent* pfile; while ((pfile = readdir(pdir))) { if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) continue; - char* uri = slv2_strjoin("file://", - path, SLV2_DIR_SEP, - pfile->d_name, SLV2_DIR_SEP, + char* uri = slv2_strjoin(file_scheme, + path, "/", + pfile->d_name, "/", NULL); - DIR* const bundle_dir = opendir(uri + 7); + DIR* const bundle_dir = opendir(uri + file_scheme_len); if (bundle_dir) { closedir(bundle_dir); SLV2Value uri_val = slv2_value_new_uri(world, uri); slv2_world_load_bundle(world, uri_val); slv2_value_free(uri_val); + } else { + SLV2_WARNF("failed to open bundle `%s'\n", uri); } free(uri); @@ -555,6 +571,25 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) closedir(pdir); } +static bool +is_path_sep(char c) +{ + return c == SLV2_PATH_SEP[0]; +} + +const char* +last_path_sep(const char* path) +{ + const size_t len = strlen(path); + const char* last_sep = path + len; + for (; last_sep > path; --last_sep) { + if (is_path_sep(*last_sep)) { + break; + } + } + return is_path_sep(*last_sep) ? last_sep : NULL; +} + /** Load all bundles found in @a lv2_path. * @param lv2_path A colon-delimited list of directories. These directories * should contain LV2 bundle directories (ie the search path is a list of @@ -565,7 +600,7 @@ slv2_world_load_path(SLV2World world, const char* lv2_path) { while (lv2_path[0] != '\0') { - const char* const sep = strchr(lv2_path, SLV2_PATH_SEP[0]); + const char* const sep = last_path_sep(lv2_path); if (sep) { const size_t dir_len = sep - lv2_path; char* const dir = malloc(dir_len + 1); |