mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
command: store val_name with its size
Compile length of val_name during compilation.
This commit is contained in:
parent
a198224666
commit
314c759a09
@ -39,7 +39,7 @@ struct cmd_name {
|
||||
/* create table of value names, e.g. String, and corresponding enum from vals.h */
|
||||
|
||||
static const struct val_name val_names[VAL_COUNT + 1] = {
|
||||
#define val(a, b, c, d) { b, d, c, a },
|
||||
#define val(a, b, c, d) { b, d, c, sizeof(c) - 1, a },
|
||||
#include "vals.h"
|
||||
#undef val
|
||||
};
|
||||
@ -214,7 +214,7 @@ static int _val_str_to_num(char *str)
|
||||
*new = '\0';
|
||||
|
||||
for (i = 0; i < VAL_COUNT; ++i)
|
||||
if (!strncmp(name, val_names[i].name, strlen(val_names[i].name)))
|
||||
if (!strncmp(name, val_names[i].name, val_names[i].name_len))
|
||||
return val_names[i].val_enum;
|
||||
|
||||
return 0;
|
||||
|
@ -241,6 +241,7 @@ struct val_name {
|
||||
int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
|
||||
const char *usage;
|
||||
const char name[30]; /* FooVal */
|
||||
uint16_t name_len; /* sizeof(FooVal) - 1 */
|
||||
uint16_t val_enum; /* foo_VAL */
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user