X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Ftest%2Futils.c;h=fa0a2022e0987368e398161bbce28d60fd43b028;hp=6870af741b188034a5a5337ae3de66c880189d71;hb=39dc9e4612339af669e934c47500605f826a2bb4;hpb=d89e5744f30b584ac4909ce1164af1289c41359b diff --git a/ccan/opt/test/utils.c b/ccan/opt/test/utils.c index 6870af74..fa0a2022 100644 --- a/ccan/opt/test/utils.c +++ b/ccan/opt/test/utils.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#include "config.h" #include #include #include @@ -35,7 +35,9 @@ static void save_err_output(const char *fmt, ...) char *p; va_start(ap, fmt); - vasprintf(&p, fmt, ap); + /* Check return, for fascist gcc */ + if (vasprintf(&p, fmt, ap) == -1) + p = NULL; va_end(ap); if (err_output) { @@ -70,33 +72,31 @@ bool parse_args(int *argc, char ***argv, ...) struct opt_table short_table[] = { /* Short opts, different args. */ - { OPT_WITHOUT_ARG("-a", test_noarg, "a"), "Description of a" }, - { OPT_WITH_ARG("-b", test_arg, show_arg, "b"), "Description of b" }, + OPT_WITHOUT_ARG("-a", test_noarg, "a", "Description of a"), + OPT_WITH_ARG("-b", test_arg, show_arg, "b", "Description of b"), OPT_ENDTABLE }; struct opt_table long_table[] = { /* Long opts, different args. */ - { OPT_WITHOUT_ARG("--ddd", test_noarg, "ddd"), "Description of ddd" }, - { OPT_WITH_ARG("--eee", test_arg, show_arg, "eee"), }, + OPT_WITHOUT_ARG("--ddd", test_noarg, "ddd", "Description of ddd"), + OPT_WITH_ARG("--eee ", test_arg, show_arg, "eee", ""), OPT_ENDTABLE }; struct opt_table long_and_short_table[] = { /* Short and long, different args. */ - { OPT_WITHOUT_ARG("--ggg/-g", test_noarg, "ggg"), - "Description of ggg" }, - { OPT_WITH_ARG("-h/--hhh", test_arg, NULL, "hhh"), - "Description of hhh"}, + OPT_WITHOUT_ARG("--ggg|-g", test_noarg, "ggg", "Description of ggg"), + OPT_WITH_ARG("-h|--hhh", test_arg, NULL, "hhh", "Description of hhh"), OPT_ENDTABLE }; /* Sub-table test. */ struct opt_table subtables[] = { /* Two short, and two long long, no description */ - { OPT_WITH_ARG("--jjj/-j/--lll/-l", test_arg, show_arg, "jjj") }, + OPT_WITH_ARG("--jjj|-j|--lll|-l", test_arg, show_arg, "jjj", ""), /* Hidden option */ - { OPT_WITH_ARG("--mmm/-m", test_arg, show_arg, "mmm"), opt_hidden }, + OPT_WITH_ARG("--mmm|-m", test_arg, show_arg, "mmm", opt_hidden), OPT_SUBTABLE(short_table, NULL), OPT_SUBTABLE(long_table, "long table options"), OPT_SUBTABLE(long_and_short_table, NULL),