Meta 'U8' corresponds to 'uint8_t'. Add virStrToLong_u8p when parsing uint8_t. Signed-off-by: Shi Lei <shi_lei@xxxxxxxxxxxxxx> --- src/util/virstring.c | 15 +++++++++++++++ src/util/virstring.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 2d0bb23..83d13ff 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -460,6 +460,21 @@ virStrToLong_uip(char const *s, char **end_ptr, int base, unsigned int *result) return 0; } +/* Just like virStrToLong_uip, above, but produce an "uint8_t" value. + * This version rejects any negative signs. */ +int +virStrToLong_u8p(char const *s, char **end_ptr, int base, uint8_t *result) +{ + unsigned int val; + int ret; + ret = virStrToLong_uip(s, end_ptr, base, &val); + if (ret < 0 || val > 0xff) + return -1; + + *result = (uint8_t) val; + return 0; +} + /* Just like virStrToLong_i, above, but produce a "long" value. */ int virStrToLong_l(char const *s, char **end_ptr, int base, long *result) diff --git a/src/util/virstring.h b/src/util/virstring.h index c528e44..da73f86 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -77,6 +77,11 @@ int virStrToLong_uip(char const *s, int base, unsigned int *result) G_GNUC_WARN_UNUSED_RESULT; +int virStrToLong_u8p(char const *s, + char **end_ptr, + int base, + uint8_t *result) + G_GNUC_WARN_UNUSED_RESULT; int virStrToLong_l(char const *s, char **end_ptr, int base, -- 2.17.1