API: NEW: function for getting all the names of the loaded modules
diff --git a/src/context.c b/src/context.c
index 3277d4a..0b979c5 100644
--- a/src/context.c
+++ b/src/context.c
@@ -251,3 +251,27 @@
return result;
}
+
+API char **
+ly_ctx_get_module_names(struct ly_ctx *ctx)
+{
+ int i;
+ char **result = NULL;
+ unsigned int count = 0;
+
+ if (!ctx) {
+ ly_errno = LY_EINVAL;
+ return NULL;
+ }
+
+ for (i = 0; i < ctx->models.used; i++) {
+ ++count;
+ result = realloc(result, count * sizeof *result);
+ result[count-1] = strdup(ctx->models.list[i]->name);
+ }
+ ++count;
+ result = realloc(result, count * sizeof *result);
+ result[count-1] = NULL;
+
+ return result;
+}
\ No newline at end of file
diff --git a/src/libyang.h b/src/libyang.h
index a8c7387..30b4bdef 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -74,6 +74,15 @@
struct ly_module *ly_ctx_get_module(struct ly_ctx *ctx, const char *name, const char *revision, int read);
/**
+ * @brief Get the names of the loaded modules.
+ *
+ * @param[in] ctx Context with the modules.
+ * @return NULL-terminated array of the module names,
+ * NULL on error. The result must be freed by the caller.
+ */
+char **ly_ctx_get_module_names(struct ly_ctx *ctx);
+
+/**
* @brief Free all internal structures of the specified context.
*
* The function should be used before terminating the application to destroy