Skip to content

Instantly share code, notes, and snippets.

@rwestphal
Created May 2, 2025 12:48
Show Gist options
  • Save rwestphal/70d6d343895c648590498908221c0774 to your computer and use it in GitHub Desktop.
Save rwestphal/70d6d343895c648590498908221c0774 to your computer and use it in GitHub Desktop.
libyang issue #2390
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <libyang/libyang.h>
#define YANG_SEARCH_PATH "/usr/local/share/yang/"
const LY_ERR module_callback(const char *mod_name, const char *mod_rev,
const char *submod_name, const char *submod_rev,
void *user_data, LYS_INFORMAT *format,
const char **module_data,
ly_module_imp_data_free_clb *free_module_data)
{
printf("Callback invoked for module: %s\n", mod_name);
return LY_ENOTFOUND;
}
int main(int argc, char **argv)
{
struct ly_ctx *ly_ctx;
/* initialization */
if (ly_ctx_new(YANG_SEARCH_PATH,
LY_CTX_NO_YANGLIBRARY | LY_CTX_PREFER_SEARCHDIRS,
&ly_ctx)
!= LY_SUCCESS)
errx(1, "ly_ctx_new(): %s", ly_errmsg(ly_ctx));
// set the import callback
ly_ctx_set_module_imp_clb(ly_ctx, module_callback, NULL);
// load module
const char *module = "holo-isis";
printf("Loading %s...\n", module);
if (ly_ctx_load_module(ly_ctx, module, NULL, NULL) == NULL)
errx(1, "ly_ctx_load_module(%s): %s", module,
ly_errmsg(ly_ctx));
/* cleanup */
ly_ctx_destroy(ly_ctx);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment