context CHANGE simplify use of ly_ctx_unset_searchpaths()
Accept searchdir string instead of the index.
diff --git a/src/context.c b/src/context.c
index 386ee05..d790c87 100644
--- a/src/context.c
+++ b/src/context.c
@@ -125,18 +125,29 @@
}
API LY_ERR
-ly_ctx_unset_searchdirs(struct ly_ctx *ctx, int index)
+ly_ctx_unset_searchdirs(struct ly_ctx *ctx, const char *value)
{
+ unsigned int index;
+
LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
- LY_CHECK_ERR_RET(index >= 0 && (unsigned int)index >= ctx->search_paths.count, LOGARG(ctx, index), LY_EINVAL);
if (!ctx->search_paths.count) {
return LY_SUCCESS;
}
- if (index >= 0) {
+ if (value) {
/* remove specific search directory */
- return ly_set_rm_index(&ctx->search_paths, index, free);
+ for (index = 0; index < ctx->search_paths.count; ++index) {
+ if (!strcmp(value, ctx->search_paths.objs[index])) {
+ break;
+ }
+ }
+ if (index == ctx->search_paths.count) {
+ LOGARG(ctx, value);
+ return LY_EINVAL;
+ } else {
+ return ly_set_rm_index(&ctx->search_paths, index, free);
+ }
} else {
/* remove them all */
ly_set_erase(&ctx->search_paths, free);
diff --git a/src/libyang.h b/src/libyang.h
index 1a117af..9b850e1 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -115,11 +115,10 @@
* @brief Clean the search path(s) from the libyang context
*
* @param[in] ctx Context to be modified.
- * @param[in] index Index of the search path to be removed, use negative value to remove them all.
- * Correct index value can be checked via ly_ctx_get_searchdirs().
+ * @param[in] value Searchdir to be removed, use NULL to remove them all.
* @return LY_ERR return value
*/
-LY_ERR ly_ctx_unset_searchdirs(struct ly_ctx *ctx, int index);
+LY_ERR ly_ctx_unset_searchdirs(struct ly_ctx *ctx, const char *value);
/**
* @brief Get the NULL-terminated list of the search paths in libyang context. Do not modify the result!