- f2 = uci_open_stream(ctx, filename, SEEK_SET, true, true);
+ if (!mktemp(filename))
+ *filename = 0;
+
+ if (!*filename) {
+ free(filename);
+ UCI_THROW(ctx, UCI_ERR_IO);
+ }
+
+ if ((stat(filename, &statbuf) == 0) && ((statbuf.st_mode & S_IFMT) != S_IFREG))
+ UCI_THROW(ctx, UCI_ERR_IO);
+
+ f2 = uci_open_stream(ctx, filename, p->path, SEEK_SET, true, true);