#include <stdarg.h>
#include <stdlib.h>
#include <ccan/opt/opt.h>
-#include <getopt.h>
#include <string.h>
#include <stdio.h>
#include "utils.h"
char *err_output = NULL;
-static void save_err_output(const char *fmt, ...)
+void save_err_output(const char *fmt, ...)
{
va_list ap;
char *p;
err_output = p;
}
-/* FIXME: This leaks, BTW. */
+void reset_options(void)
+{
+ opt_free_table();
+ free(err_output);
+ err_output = NULL;
+}
+
+static bool allocated = false;
+
bool parse_args(int *argc, char ***argv, ...)
{
char **a;
(*argc)++;
a = realloc(a, sizeof(*a) * (*argc + 1));
}
+
+ if (allocated)
+ free(*argv);
+
*argv = a;
- /* Re-set before parsing. */
- optind = 0;
+ allocated = true;
return opt_parse(argc, *argv, save_err_output);
}