- /* create the new argv */
- int num_args;
- for (num_args = 0; start_argv[num_args] != NULL; num_args++)
- ;
- char **new_argv = scalloc((num_args + 3) * sizeof(char *));
-
- /* copy the arguments, but skip the ones we'll replace */
- int write_index = 0;
- bool skip_next = false;
- for (int i = 0; i < num_args; ++i) {
- if (skip_next)
- skip_next = false;
- else if (!strcmp(start_argv[i], "-r") ||
- !strcmp(start_argv[i], "--restart"))
- skip_next = true;
- else
- new_argv[write_index++] = start_argv[i];
- }
-
- /* add the arguments we'll replace */
- new_argv[write_index++] = "--restart";
- new_argv[write_index] = restart_filename;
-
- /* swap the argvs */
- start_argv = new_argv;
+ start_argv = add_argument(start_argv, "--restart", restart_filename, "-r");