int changes = 0;
UCI_TRAP_SAVE(ctx, done);
- stream = uci_open_stream(ctx, filename, SEEK_SET, flush, false);
+ stream = uci_open_stream(ctx, filename, NULL, SEEK_SET, flush, false);
if (p)
changes = uci_parse_delta(ctx, stream, p);
UCI_TRAP_RESTORE(ctx);
UCI_THROW(ctx, UCI_ERR_MEM);
UCI_TRAP_SAVE(ctx, done);
- f = uci_open_stream(ctx, filename, SEEK_SET, true, false);
+ f = uci_open_stream(ctx, filename, NULL, SEEK_SET, true, false);
pctx->file = f;
while (!feof(f)) {
struct uci_element *e;
ctx->err = 0;
UCI_TRAP_SAVE(ctx, done);
- f = uci_open_stream(ctx, filename, SEEK_END, true, true);
+ f = uci_open_stream(ctx, filename, NULL, SEEK_END, true, true);
UCI_TRAP_RESTORE(ctx);
uci_foreach_element_safe(&p->delta, tmp, e) {
UCI_THROW(ctx, UCI_ERR_IO);
/* open the config file for writing now, so that it is locked */
- f1 = uci_open_stream(ctx, p->path, SEEK_SET, true, true);
+ f1 = uci_open_stream(ctx, p->path, NULL, SEEK_SET, true, true);
/* flush unsaved changes and reload from delta file */
UCI_TRAP_SAVE(ctx, done);
goto done;
}
- f2 = uci_open_stream(ctx, filename, SEEK_SET, true, true);
+ f2 = uci_open_stream(ctx, filename, p->path, SEEK_SET, true, true);
uci_export(ctx, f2, p, false);
fflush(f2);
}
UCI_TRAP_SAVE(ctx, done);
- file = uci_open_stream(ctx, filename, SEEK_SET, false, false);
+ file = uci_open_stream(ctx, filename, NULL, SEEK_SET, false, false);
ctx->err = 0;
UCI_INTERNAL(uci_import, ctx, file, name, &package, true);
UCI_TRAP_RESTORE(ctx);
__private void uci_free_delta(struct uci_delta *h);
__private struct uci_package *uci_alloc_package(struct uci_context *ctx, const char *name);
-__private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, int pos, bool write, bool create);
+__private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, const char *origfilename, int pos, bool write, bool create);
__private void uci_close_stream(FILE *stream);
__private void uci_getln(struct uci_context *ctx, int offset);
* note: when opening for write and seeking to the beginning of
* the stream, truncate the file
*/
-__private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, int pos, bool write, bool create)
+__private FILE *uci_open_stream(struct uci_context *ctx, const char *filename, const char *origfilename, int pos, bool write, bool create)
{
struct stat statbuf;
FILE *file = NULL;
if (create) {
flags |= O_CREAT;
- name = basename((char *) filename);
+ if (origfilename) {
+ name = basename((char *) origfilename);
+ } else {
+ name = basename((char *) filename);
+ }
if ((asprintf(&filename2, "%s/%s", ctx->confdir, name) < 0) || !filename2) {
UCI_THROW(ctx, UCI_ERR_MEM);
} else {