diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-05 18:23:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-11-05 18:23:30 +0000 |
commit | 4ed089396bc7f14bcb94e80f0f9f4757fd8c48b7 (patch) | |
tree | 866986558761a9709a7af1940ba607128a45f775 /util/argconfig.c | |
parent | Releasing debian version 2.1.2-2. (diff) | |
download | nvme-cli-4ed089396bc7f14bcb94e80f0f9f4757fd8c48b7.tar.xz nvme-cli-4ed089396bc7f14bcb94e80f0f9f4757fd8c48b7.zip |
Merging upstream version 2.2.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | util/argconfig.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/util/argconfig.c b/util/argconfig.c index d09ba9d..2c328ff 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -488,6 +488,51 @@ int argconfig_parse_comma_sep_array(char *string, int *val, } } +int argconfig_parse_comma_sep_array_short(char *string, unsigned short *val, + unsigned max_length) +{ + int ret = 0; + unsigned long v; + char *tmp; + char *p; + + if (!string || !strlen(string)) + return 0; + + tmp = strtok(string, ","); + if (!tmp) + return 0; + + v = strtoul(tmp, &p, 0); + if (*p != 0) + return -1; + if (v > UINT16_MAX) { + fprintf(stderr, "%s out of range\n", tmp); + return -1; + } + val[ret] = v; + ret++; + + while (1) { + tmp = strtok(NULL, ","); + if (tmp == NULL) + return ret; + + if (ret >= max_length) + return -1; + + v = strtoul(tmp, &p, 0); + if (*p != 0) + return -1; + if (v > UINT16_MAX) { + fprintf(stderr, "%s out of range\n", tmp); + return -1; + } + val[ret] = v; + ret++; + } +} + int argconfig_parse_comma_sep_array_long(char *string, unsigned long long *val, unsigned max_length) |