+
+ while (len)
+ {
+ obj = json_tokener_parse_ex(tok, buf, len);
+ *err = json_tokener_get_error(tok);
+
+ if (*err == json_tokener_success)
+ {
+ if (array)
+ {
+ json_object_array_add(array, obj);
+ }
+ else
+ {
+ break;
+ }
+ }
+ else if (*err != json_tokener_continue)
+ {
+ break;
+ }
+
+ buf += tok->char_offset;
+ len -= tok->char_offset;
+ }
+
+ return obj;
+}
+
+static struct json_object *
+parse_json(FILE *fd, const char *source, const char **error, bool array_mode)
+{
+ size_t len;
+ char buf[256];
+ struct json_object *obj = NULL, *array = NULL;