*/
static FILE *uci_open_stream(struct uci_context *ctx, const char *filename, int pos, bool write)
{
+ struct stat statbuf;
FILE *file = NULL;
int fd, ret;
+ if (!write && ((stat(filename, &statbuf) < 0) ||
+ ((statbuf.st_mode & S_IFMT) != S_IFREG))) {
+ UCI_THROW(ctx, UCI_ERR_NOTFOUND);
+ }
+
fd = open(filename, (write ? O_RDWR | O_CREAT : O_RDONLY));
if (fd <= 0)
goto error;
int uci_load(struct uci_context *ctx, const char *name, struct uci_package **package)
{
- struct stat statbuf;
char *filename;
bool confdir;
FILE *file = NULL;
break;
}
- if ((stat(filename, &statbuf) < 0) ||
- ((statbuf.st_mode & S_IFMT) != S_IFREG)) {
- UCI_THROW(ctx, UCI_ERR_NOTFOUND);
- }
-
file = uci_open_stream(ctx, filename, SEEK_SET, false);
ctx->errno = 0;
UCI_TRAP_SAVE(ctx, done);