uci_file_cleanup(ctx);
}
+static void uci_load_history_file(struct uci_context *ctx, struct uci_package *p, char *filename, FILE **f, bool flush)
+{
+ FILE *stream = NULL;
+
+ UCI_TRAP_SAVE(ctx, done);
+ stream = uci_open_stream(ctx, filename, SEEK_SET, flush, false);
+ if (p)
+ uci_parse_history(ctx, stream, p);
+ UCI_TRAP_RESTORE(ctx);
+done:
+ if (f)
+ *f = stream;
+ else if (stream)
+ uci_close_stream(stream);
+}
+
static void uci_load_history(struct uci_context *ctx, struct uci_package *p, bool flush)
{
+ struct uci_element *e;
char *filename = NULL;
FILE *f = NULL;
if (!p->confdir)
return;
- if ((asprintf(&filename, "%s/%s", UCI_SAVEDIR, p->e.name) < 0) || !filename)
- UCI_THROW(ctx, UCI_ERR_MEM);
+ uci_foreach_element(&ctx->history_path, e) {
+ if ((asprintf(&filename, "%s/%s", e->name, p->e.name) < 0) || !filename)
+ UCI_THROW(ctx, UCI_ERR_MEM);
- UCI_TRAP_SAVE(ctx, done);
- f = uci_open_stream(ctx, filename, SEEK_SET, flush, false);
- if (p)
- uci_parse_history(ctx, f, p);
- UCI_TRAP_RESTORE(ctx);
+ uci_load_history_file(ctx, p, filename, NULL, false);
+ free(filename);
+ }
-done:
+ if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
+ UCI_THROW(ctx, UCI_ERR_MEM);
+
+ uci_load_history_file(ctx, p, filename, &f, flush);
if (flush && f) {
rewind(f);
ftruncate(fileno(f), 0);
char *filename;
UCI_ASSERT(ctx, uci_validate_name(name));
- filename = uci_malloc(ctx, strlen(name) + sizeof(UCI_CONFDIR) + 2);
- sprintf(filename, UCI_CONFDIR "/%s", name);
+ filename = uci_malloc(ctx, strlen(name) + strlen(ctx->confdir) + 2);
+ sprintf(filename, "%s/%s", ctx->confdir, name);
return filename;
}
if (uci_list_empty(&p->history))
return 0;
- if ((asprintf(&filename, "%s/%s", UCI_SAVEDIR, p->e.name) < 0) || !filename)
+ if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
UCI_THROW(ctx, UCI_ERR_MEM);
ctx->errno = 0;
glob_t globbuf;
int size, i;
char *buf;
+ char *dir;
UCI_HANDLE_ERR(ctx);
- if (glob(UCI_CONFDIR "/*", GLOB_MARK, NULL, &globbuf) != 0)
+ dir = uci_malloc(ctx, strlen(ctx->confdir) + 1 + sizeof("/*"));
+ sprintf(dir, "%s/*", ctx->confdir);
+ if (glob(dir, GLOB_MARK, NULL, &globbuf) != 0)
UCI_THROW(ctx, UCI_ERR_NOTFOUND);
size = sizeof(char *) * (globbuf.gl_pathc + 1);
buf += strlen(buf) + 1;
}
*list = configs;
+ free(dir);
return 0;
}