]> git.ozlabs.org Git - ccan/blobdiff - ccan/opt/test/utils.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / opt / test / utils.c
index c2967fca173d51010b810fcaa626eb6ebff420df..61199fb4676dbdeaa8a5cdf81a6fba7a27d5de5d 100644 (file)
@@ -8,7 +8,7 @@
 #include "utils.h"
 
 unsigned int test_cb_called;
 #include "utils.h"
 
 unsigned int test_cb_called;
-char *test_noarg(void *arg)
+char *test_noarg(void *arg UNNEEDED)
 {
        test_cb_called++;
        return NULL;
 {
        test_cb_called++;
        return NULL;
@@ -21,9 +21,10 @@ char *test_arg(const char *optarg, const char *arg)
        return NULL;
 }
 
        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;
 }
 
 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);
 }
 
        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"),
 struct opt_table short_table[] = {
        /* Short opts, different args. */
        OPT_WITHOUT_ARG("-a", test_noarg, "a", "Description of a"),