1
0
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:
Zdenek Kabelac 2024-05-22 17:15:20 +02:00
parent a198224666
commit 314c759a09
2 changed files with 3 additions and 2 deletions

View File

@ -39,7 +39,7 @@ struct cmd_name {
/* create table of value names, e.g. String, and corresponding enum from vals.h */ /* create table of value names, e.g. String, and corresponding enum from vals.h */
static const struct val_name val_names[VAL_COUNT + 1] = { 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" #include "vals.h"
#undef val #undef val
}; };
@ -214,7 +214,7 @@ static int _val_str_to_num(char *str)
*new = '\0'; *new = '\0';
for (i = 0; i < VAL_COUNT; ++i) 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 val_names[i].val_enum;
return 0; return 0;

View File

@ -241,6 +241,7 @@ struct val_name {
int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */ int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */
const char *usage; const char *usage;
const char name[30]; /* FooVal */ const char name[30]; /* FooVal */
uint16_t name_len; /* sizeof(FooVal) - 1 */
uint16_t val_enum; /* foo_VAL */ uint16_t val_enum; /* foo_VAL */
}; };