Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib subcmd: Introduce OPTION_ULONG

For completeness, will be used in 'perf trace --max-events'.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-glaj3pwespxfj2fdjs9a20b6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+21
+19
tools/lib/subcmd/parse-options.c
··· 116 116 case OPTION_INTEGER: 117 117 case OPTION_UINTEGER: 118 118 case OPTION_LONG: 119 + case OPTION_ULONG: 119 120 case OPTION_U64: 120 121 default: 121 122 break; ··· 167 166 case OPTION_INTEGER: 168 167 case OPTION_UINTEGER: 169 168 case OPTION_LONG: 169 + case OPTION_ULONG: 170 170 case OPTION_U64: 171 171 default: 172 172 break; ··· 293 291 if (get_arg(p, opt, flags, &arg)) 294 292 return -1; 295 293 *(long *)opt->value = strtol(arg, (char **)&s, 10); 294 + if (*s) 295 + return opterror(opt, "expects a numerical value", flags); 296 + return 0; 297 + 298 + case OPTION_ULONG: 299 + if (unset) { 300 + *(unsigned long *)opt->value = 0; 301 + return 0; 302 + } 303 + if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { 304 + *(unsigned long *)opt->value = opt->defval; 305 + return 0; 306 + } 307 + if (get_arg(p, opt, flags, &arg)) 308 + return -1; 309 + *(unsigned long *)opt->value = strtoul(arg, (char **)&s, 10); 296 310 if (*s) 297 311 return opterror(opt, "expects a numerical value", flags); 298 312 return 0; ··· 721 703 case OPTION_ARGUMENT: 722 704 break; 723 705 case OPTION_LONG: 706 + case OPTION_ULONG: 724 707 case OPTION_U64: 725 708 case OPTION_INTEGER: 726 709 case OPTION_UINTEGER:
+2
tools/lib/subcmd/parse-options.h
··· 25 25 OPTION_STRING, 26 26 OPTION_INTEGER, 27 27 OPTION_LONG, 28 + OPTION_ULONG, 28 29 OPTION_CALLBACK, 29 30 OPTION_U64, 30 31 OPTION_UINTEGER, ··· 134 133 #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } 135 134 #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } 136 135 #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } 136 + #define OPT_ULONG(s, l, v, h) { .type = OPTION_ULONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned long *), .help = (h) } 137 137 #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } 138 138 #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), .argh = (a), .help = (h) } 139 139 #define OPT_STRING_OPTARG(s, l, v, a, h, d) \