Skip to content

Commit

Permalink
Use semicolon as a directory delimiter on Windows
Browse files Browse the repository at this point in the history
Windows path names have ':' inside as a drive letter separator. The
widespread convention on that platform is to use ';' as a list separator
in file paths, so let's follow suite.

It looks like this multi-value searchdir is only used in `ly_ctx_new()`,
and that all other functions operate on one directory at a time.
  • Loading branch information
jktjkt authored and michalvasko committed Dec 16, 2021
1 parent b1aa77f commit 34bb928
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
2 changes: 1 addition & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion tests/utests/basic/test_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 34bb928

Please sign in to comment.