X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Futils.c;h=2ff04884ebdc0efe6dc4d9dd8fe4ae6af4b9175b;hp=c2967fca173d51010b810fcaa626eb6ebff420df;hb=HEAD;hpb=50212d0d271f967d9f5d14c116ec54c0050882a8 diff --git a/ccan/opt/test/utils.c b/ccan/opt/test/utils.c index c2967fca..61199fb4 100644 --- a/ccan/opt/test/utils.c +++ b/ccan/opt/test/utils.c @@ -8,7 +8,7 @@ #include "utils.h" unsigned int test_cb_called; -char *test_noarg(void *arg) +char *test_noarg(void *arg UNNEEDED) { test_cb_called++; return NULL; @@ -21,9 +21,10 @@ char *test_arg(const char *optarg, const char *arg) return NULL; } -void show_arg(char buf[OPT_SHOW_LEN], const char *arg) +bool show_arg(char *buf, size_t len, const char *arg) { - strncpy(buf, arg, OPT_SHOW_LEN); + strncpy(buf, arg, len); + return true; } char *err_output = NULL; @@ -103,6 +104,29 @@ bool parse_early_args(int *argc, char ***argv, ...) return opt_early_parse(*argc, *argv, save_err_output); } +bool parse_early_args_incomplete(int *argc, char ***argv, ...) +{ + char **a; + va_list ap; + + va_start(ap, argv); + *argc = 1; + a = malloc(sizeof(*a) * (*argc + 1)); + a[0] = (*argv)[0]; + while ((a[*argc] = va_arg(ap, char *)) != NULL) { + (*argc)++; + a = realloc(a, sizeof(*a) * (*argc + 1)); + } + + if (allocated) + free(*argv); + + *argv = a; + allocated = true; + + return opt_early_parse_incomplete(*argc, *argv, save_err_output); +} + struct opt_table short_table[] = { /* Short opts, different args. */ OPT_WITHOUT_ARG("-a", test_noarg, "a", "Description of a"),