if (!pctx)
return;
+ ctx->pctx = NULL;
if (pctx->cfg) {
uci_list_del(&pctx->cfg->list);
- uci_drop_file(pctx->cfg);
+ uci_drop_config(pctx->cfg);
}
if (pctx->buf)
free(pctx->buf);
type = next_arg(ctx, str, true);
name = next_arg(ctx, str, false);
assert_eol(ctx, str);
-
- DPRINTF("Section<%s>: %s\n", type, name);
}
/*
name = next_arg(ctx, str, true);
value = next_arg(ctx, str, true);
assert_eol(ctx, str);
-
- DPRINTF("\tOption: %s=\"%s\"\n", name, value);
}
/*
}
}
-int uci_load(struct uci_context *ctx, const char *name)
+int uci_load(struct uci_context *ctx, const char *name, struct uci_config **cfg)
{
struct uci_parse_context *pctx;
struct stat statbuf;
UCI_HANDLE_ERR(ctx);
UCI_ASSERT(ctx, name != NULL);
+ UCI_TRAP_SAVE(ctx, ignore);
+ uci_unload(ctx, name);
+ UCI_TRAP_RESTORE(ctx);
+
+ignore:
/* make sure no memory from previous parse attempts is leaked */
uci_parse_cleanup(ctx);
if (!pctx->file)
UCI_THROW(ctx, UCI_ERR_IO);
- pctx->cfg = uci_alloc_file(ctx, name);
+ pctx->cfg = uci_alloc_config(ctx, name);
while (!feof(pctx->file)) {
uci_getln(ctx);
/* add to main config file list */
uci_list_add(&ctx->root, &pctx->cfg->list);
+ if (cfg)
+ *cfg = pctx->cfg;
+
pctx->cfg = NULL;
/* no error happened, we can get rid of the parser context now */