+static bool early_parse(int argc, char *argv[],
+ void (*errlog)(const char *fmt, ...),
+ bool ignore_unknown)
+{
+ int ret;
+ unsigned off = 0;
+ char **tmpargv = opt_alloc.alloc(sizeof(argv[0]) * (argc + 1));
+
+ /* We could avoid a copy and skip instead, but this is simple. */
+ memcpy(tmpargv, argv, sizeof(argv[0]) * (argc + 1));
+
+ /* This helps opt_usage. */
+ opt_argv0 = argv[0];
+
+ while ((ret = parse_one(&argc, tmpargv, OPT_EARLY, &off, errlog, ignore_unknown)) == 1);
+
+ opt_alloc.free(tmpargv);
+
+ /* parse_one returns 0 on finish, -1 on error */
+ return (ret == 0);
+}
+
+bool opt_early_parse(int argc, char *argv[],
+ void (*errlog)(const char *fmt, ...))
+{
+ return early_parse(argc, argv, errlog, false);
+}
+
+bool opt_early_parse_incomplete(int argc, char *argv[],
+ void (*errlog)(const char *fmt, ...))
+{
+ return early_parse(argc, argv, errlog, true);
+}
+