]> git.ozlabs.org Git - ccan/blobdiff - ccan/opt/usage.c
opt: complete coverage, enhance opt_free_table.
[ccan] / ccan / opt / usage.c
index 60e1586861adc0981a5bf0eaf00bc63bcff450a4..873ee5db1856cf0bf326a8ed4ba9f19aa22c2db6 100644 (file)
@@ -1,3 +1,4 @@
+/* Licensed under GPLv3+ - see LICENSE file for details */
 #include <ccan/opt/opt.h>
 #include <string.h>
 #include <stdlib.h>
@@ -32,8 +33,8 @@ char *opt_usage(const char *argv0, const char *extra)
                extra = "";
                for (i = 0; i < opt_count; i++) {
                        if (opt_table[i].cb == (void *)opt_usage_and_exit
-                           && opt_table[i].arg) {
-                               extra = opt_table[i].arg;
+                           && opt_table[i].u.carg) {
+                               extra = opt_table[i].u.carg;
                                break;
                        }
                }
@@ -62,9 +63,6 @@ char *opt_usage(const char *argv0, const char *extra)
        }
 
        p = ret = malloc(len);
-       if (!ret)
-               return NULL;
-
        p += sprintf(p, "Usage: %s", argv0);
        p += sprintf(p, " [-");
        num = write_short_options(p);
@@ -100,7 +98,7 @@ char *opt_usage(const char *argv0, const char *extra)
                if (opt_table[i].show) {
                        char buf[OPT_SHOW_LEN + sizeof("...")];
                        strcpy(buf + OPT_SHOW_LEN, "...");
-                       opt_table[i].show(buf, opt_table[i].arg);
+                       opt_table[i].show(buf, opt_table[i].u.arg);
                        len += sprintf(p + len, " (default: %s)", buf);
                }
                p += len;