if (!p->confdir)
return;
- 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);
UCI_TRAP_SAVE(ctx, done);
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;
}
#include "uci.h"
#include "err.h"
+static const char *uci_confdir = UCI_CONFDIR;
+static const char *uci_savedir = UCI_SAVEDIR;
+
static const char *uci_errstr[] = {
[UCI_OK] = "Success",
[UCI_ERR_MEM] = "Out of memory",
uci_list_init(&ctx->root);
ctx->flags = UCI_FLAG_STRICT;
+ ctx->confdir = (char *) uci_confdir;
+ ctx->savedir = (char *) uci_savedir;
+
return ctx;
}
{
struct uci_element *e, *tmp;
+ if (ctx->confdir != uci_confdir)
+ free(ctx->confdir);
+ if (ctx->savedir != uci_savedir)
+ free(ctx->savedir);
+
UCI_TRAP_SAVE(ctx, ignore);
uci_cleanup(ctx);
uci_foreach_element_safe(&ctx->root, tmp, e) {
return;
}
+int uci_set_confdir(struct uci_context *ctx, char *dir)
+{
+ dir = uci_strdup(ctx, dir);
+ if (ctx->confdir != uci_confdir)
+ free(ctx->confdir);
+ ctx->confdir = dir;
+ return 0;
+}
+
+int uci_set_savedir(struct uci_context *ctx, char *dir)
+{
+ dir = uci_strdup(ctx, dir);
+ if (ctx->savedir != uci_savedir)
+ free(ctx->savedir);
+ ctx->savedir = dir;
+ return 0;
+}
+
int uci_cleanup(struct uci_context *ctx)
{
UCI_HANDLE_ERR(ctx);
/**
* uci_list_configs: List available uci config files
- *
* @ctx: uci context
*/
extern int uci_list_configs(struct uci_context *ctx, char ***list);
+/**
+ * uci_set_savedir: override the default history save directory
+ * @ctx: uci context
+ * @dir: directory name
+ */
+extern int uci_set_savedir(struct uci_context *ctx, char *dir);
+
+/**
+ * uci_set_savedir: override the default config storage directory
+ * @ctx: uci context
+ * @dir: directory name
+ */
+extern int uci_set_confdir(struct uci_context *ctx, char *dir);
+
+
/* UCI data structures */
enum uci_type {
UCI_TYPE_HISTORY = 0,
/* uci runtime flags */
enum uci_flags flags;
+ char *confdir;
+ char *savedir;
+
/* private: */
int errno;
const char *func;