X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=file.c;h=b8aa8653377fe43afb12e9b7beb7e25e5fa8ab60;hb=396dd7a78674c5afc08240b91b045f366b54face;hp=7a576128c038ef81ffe777e34c80b0b43d2c3d95;hpb=8e57ddf6b61e9e95e1f319b1def18789f19f9ee1;p=project%2Fuci.git diff --git a/file.c b/file.c index 7a57612..b8aa865 100644 --- a/file.c +++ b/file.c @@ -526,9 +526,15 @@ int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u */ 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; @@ -645,7 +651,6 @@ done: int uci_load(struct uci_context *ctx, const char *name, struct uci_package **package) { - struct stat statbuf; char *filename; bool confdir; FILE *file = NULL; @@ -675,11 +680,6 @@ int uci_load(struct uci_context *ctx, const char *name, struct uci_package **pac 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);