-}
-
-int uci_load(struct uci_context *ctx, const char *name)
-{
- struct uci_parse_context *pctx;
- struct stat statbuf;
- char *filename;
-
- UCI_HANDLE_ERR(ctx);
- UCI_ASSERT(ctx, name != NULL);
-
- /* make sure no memory from previous parse attempts is leaked */
- uci_parse_cleanup(ctx);
-
- pctx = (struct uci_parse_context *) uci_malloc(ctx, sizeof(struct uci_parse_context));
- ctx->pctx = pctx;
-
- switch (name[0]) {
- case '.':
- case '/':
- /* absolute/relative path outside of /etc/config */
- filename = (char *) name;
- break;
- default:
- filename = uci_malloc(ctx, strlen(name) + sizeof(UCI_CONFDIR) + 2);
- sprintf(filename, UCI_CONFDIR "/%s", name);
- break;
- }
-
- if ((stat(filename, &statbuf) < 0) ||
- ((statbuf.st_mode & S_IFMT) != S_IFREG))
- UCI_THROW(ctx, UCI_ERR_NOTFOUND);
-
- pctx->file = fopen(filename, "r");
- if (!pctx->file)
- UCI_THROW(ctx, UCI_ERR_IO);
-
- pctx->cfg = uci_alloc_file(ctx, name);
-
- while (!feof(pctx->file)) {
- uci_getln(ctx);
- if (*(pctx->buf))
- uci_parse_line(ctx);
- }
-
- /* add to main config file list */
- uci_list_add(&ctx->root, &pctx->cfg->list);
- pctx->cfg = NULL;
-
- /* if no error happened, we can get rid of the parser context now */
- uci_parse_cleanup(ctx);