ofs += strlen(p);
if (pctx->buf[ofs - 1] == '\n') {
pctx->line++;
- pctx->buf[ofs - 1] = 0;
+ if (ofs >= 2 && pctx->buf[ofs - 2] == '\r')
+ pctx->buf[ofs - 2] = 0;
+ else
+ pctx->buf[ofs - 1] = 0;
return;
}
struct uci_element *s, *o, *i;
if (header)
- fprintf(stream, "package '%s'\n", uci_escape(ctx, p->e.name));
+ fprintf(stream, "package %s\n", uci_escape(ctx, p->e.name));
uci_foreach_element(&p->sections, s) {
struct uci_section *sec = uci_to_section(s);
- fprintf(stream, "\nconfig '%s'", uci_escape(ctx, sec->type));
+ fprintf(stream, "\nconfig %s", uci_escape(ctx, sec->type));
if (!sec->anonymous || (ctx->flags & UCI_FLAG_EXPORT_NAME))
fprintf(stream, " '%s'", uci_escape(ctx, sec->e.name));
fprintf(stream, "\n");
struct uci_option *opt = uci_to_option(o);
switch(opt->type) {
case UCI_TYPE_STRING:
- fprintf(stream, "\toption '%s'", uci_escape(ctx, opt->e.name));
+ fprintf(stream, "\toption %s", uci_escape(ctx, opt->e.name));
fprintf(stream, " '%s'\n", uci_escape(ctx, opt->v.string));
break;
case UCI_TYPE_LIST:
uci_foreach_element(&opt->v.list, i) {
- fprintf(stream, "\tlist '%s'", uci_escape(ctx, opt->e.name));
+ fprintf(stream, "\tlist %s", uci_escape(ctx, opt->e.name));
fprintf(stream, " '%s'\n", uci_escape(ctx, i->name));
}
break;
break;
}
+ UCI_TRAP_SAVE(ctx, done);
file = uci_open_stream(ctx, filename, SEEK_SET, false, false);
ctx->err = 0;
- UCI_TRAP_SAVE(ctx, done);
UCI_INTERNAL(uci_import, ctx, file, name, &package, true);
UCI_TRAP_RESTORE(ctx);
done:
uci_close_stream(file);
- if (ctx->err)
+ if (ctx->err) {
+ free(filename);
UCI_THROW(ctx, ctx->err);
+ }
return package;
}