diff --git a/src/common.h b/src/common.h index 44309623a..7e80b1ec6 100644 --- a/src/common.h +++ b/src/common.h @@ -629,4 +629,10 @@ LY_ERR ly_munmap(void *addr, size_t length); */ LY_ERR ly_strcat(char **dest, const char *format, ...); +#ifndef _WIN32 +# define PATH_SEPARATOR ":" +#else +# define PATH_SEPARATOR ";" +#endif + #endif /* LY_COMMON_H_ */ diff --git a/src/context.c b/src/context.c index 28a72f14c..a29f5fb6b 100644 --- a/src/context.c +++ b/src/context.c @@ -258,7 +258,7 @@ ly_ctx_new(const char *search_dir, uint16_t options, struct ly_ctx **new_ctx) search_dir_list = strdup(search_dir); LY_CHECK_ERR_GOTO(!search_dir_list, LOGMEM(NULL); rc = LY_EMEM, cleanup); - for (dir = search_dir_list; (sep = strchr(dir, ':')) != NULL && rc == LY_SUCCESS; dir = sep + 1) { + for (dir = search_dir_list; (sep = strchr(dir, PATH_SEPARATOR[0])) != NULL && rc == LY_SUCCESS; dir = sep + 1) { *sep = 0; rc = ly_ctx_set_searchdir(ctx, dir); if (rc == LY_EEXIST) { diff --git a/src/context.h b/src/context.h index 185923626..fdd87e231 100644 --- a/src/context.h +++ b/src/context.h @@ -214,8 +214,9 @@ struct ly_ctx; * also affects the number of instances of both tree types. While you can have only one instance of * specific schema connected with a single context, number of data tree instances is not connected. * - * @param[in] search_dir Directory where libyang will search for the imported or included modules - * and submodules. If no such directory is available, NULL is accepted. + * @param[in] search_dir Directory (or directories) where libyang will search for the imported or included modules + * and submodules. If no such directory is available, NULL is accepted. Several directories can be specified, + * delimited by colon ":" (on Windows, use semicolon ";" instead). * @param[in] options Context options, see @ref contextoptions. * @param[out] new_ctx Pointer to the created libyang context if LY_SUCCESS returned. * @return LY_ERR return value. diff --git a/tests/utests/basic/test_context.c b/tests/utests/basic/test_context.c index 9ec92035c..f542bc26f 100644 --- a/tests/utests/basic/test_context.c +++ b/tests/utests/basic/test_context.c @@ -104,7 +104,9 @@ test_searchdirs(void **state) /* test searchdir list in ly_ctx_new() */ assert_int_equal(LY_EINVAL, ly_ctx_new("/nonexistingfile", 0, &UTEST_LYCTX)); CHECK_LOG("Unable to use search directory \"/nonexistingfile\" (No such file or directory).", NULL); - assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_SRC ":"TESTS_BIN ":"TESTS_BIN ":"TESTS_SRC, LY_CTX_DISABLE_SEARCHDIRS, &UTEST_LYCTX)); + assert_int_equal(LY_SUCCESS, + ly_ctx_new(TESTS_SRC PATH_SEPARATOR TESTS_BIN PATH_SEPARATOR TESTS_BIN PATH_SEPARATOR TESTS_SRC, + LY_CTX_DISABLE_SEARCHDIRS, &UTEST_LYCTX)); assert_int_equal(2, UTEST_LYCTX->search_paths.count); assert_string_equal(TESTS_SRC, UTEST_LYCTX->search_paths.objs[0]); assert_string_equal(TESTS_BIN, UTEST_LYCTX->search_paths.objs[1]);