+ return 0;
+
+error:
+ memset(ptr, 0, sizeof(struct uci_ptr));
+ UCI_THROW(ctx, UCI_ERR_PARSE);
+}
+
+
+__private void uci_parse_error(struct uci_context *ctx, char *pos, char *reason)
+{
+ struct uci_parse_context *pctx = ctx->pctx;
+
+ pctx->reason = reason;
+ pctx->byte = pos - pctx->buf;
+ UCI_THROW(ctx, UCI_ERR_PARSE);
+}
+
+
+
+/*
+ * open a stream and go to the right position
+ *
+ * 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)
+{
+ struct stat statbuf;
+ FILE *file = NULL;
+ int fd, ret;
+ int mode = (write ? O_RDWR : O_RDONLY);
+
+ if (create)
+ mode |= O_CREAT;
+
+ if (!write && ((stat(filename, &statbuf) < 0) ||
+ ((statbuf.st_mode & S_IFMT) != S_IFREG))) {
+ UCI_THROW(ctx, UCI_ERR_NOTFOUND);