X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=strutil.c;h=6a9d86226a7ac15d59f285bebfb25b8a42c175d4;hb=c5d660ae244babd4afc7863ba23f66d31af6e29e;hp=380d78f59efdbb0bf72009c903484a85d9f87a06;hpb=4d436e71ba6059b217a3d90775033e850944ad42;p=libsigrok.git diff --git a/strutil.c b/strutil.c index 380d78f5..6a9d8622 100644 --- a/strutil.c +++ b/strutil.c @@ -186,19 +186,19 @@ char **sr_parse_triggerstring(struct sr_device *device, * Spaces (but not other whitespace) between value and suffix are allowed. * * @param sizestring A string containing a (decimal) size value. - * @return The string's size value as uint64_t. + * @param size Pointer to uint64_t which will contain the string's size value. + * @return SR_OK or error code * - * TODO: Error handling. */ -uint64_t sr_parse_sizestring(const char *sizestring) +int sr_parse_sizestring(const char *sizestring, uint64_t *size) { - int multiplier; - uint64_t val; + int multiplier, done; char *s; - val = strtoull(sizestring, &s, 10); + *size = strtoull(sizestring, &s, 10); multiplier = 0; - while (s && *s && multiplier == 0) { + done = FALSE; + while (s && *s && multiplier == 0 && !done) { switch (*s) { case ' ': break; @@ -215,15 +215,18 @@ uint64_t sr_parse_sizestring(const char *sizestring) multiplier = SR_GHZ(1); break; default: - val = 0; - multiplier = -1; + done = TRUE; + s--; } s++; } if (multiplier > 0) - val *= multiplier; + *size *= multiplier; + + if (*s && strcasecmp(s, "Hz")) + return SR_ERR; - return val; + return SR_OK; } /**