X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Futils.c;h=2ff04884ebdc0efe6dc4d9dd8fe4ae6af4b9175b;hp=a9bedf2e0063333060a597a3bd591ff76744ab00;hb=HEAD;hpb=ad2ce76c10f808283ea7cf25cd8e76a15710c4f3 diff --git a/ccan/opt/test/utils.c b/ccan/opt/test/utils.c index a9bedf2e..61199fb4 100644 --- a/ccan/opt/test/utils.c +++ b/ccan/opt/test/utils.c @@ -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"),