+static int handle_option(struct fio_option *o, const char *ptr, void *data)
+{
+ const char *ptr2 = NULL;
+ int r1, r2;
+
+ /*
+ * See if we have a second set of parameters, hidden after a comma.
+ * Do this before parsing the first round, to check if we should
+ * copy set 1 options to set 2.
+ */
+ if (ptr)
+ ptr2 = strchr(ptr, ',');
+
+ /*
+ * Don't return early if parsing the first option fails - if
+ * we are doing multiple arguments, we can allow the first one
+ * being empty.
+ */
+ r1 = __handle_option(o, ptr, data, 1, !!ptr2);
+
+ if (!ptr2)
+ return r1;
+
+ ptr2++;
+ r2 = __handle_option(o, ptr2, data, 0, 0);
+
+ return r1 && r2;
+}
+
+int parse_cmd_option(const char *opt, const char *val,
+ struct fio_option *options, void *data)
+{
+ struct fio_option *o;
+
+ o = find_option(options, opt);
+ if (!o) {
+ fprintf(stderr, "Bad option %s\n", opt);
+ return 1;
+ }
+
+ if (!handle_option(o, val, data))
+ return 0;
+
+ fprintf(stderr, "fio: failed parsing %s=%s\n", opt, val);
+ return 1;
+}
+