X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstrutil.c;h=5344ec2903218bef4c7e9baabd3412d10b7929e5;hb=972398f471696e6c8995f7066d6f5a4a1d2b3552;hp=30e992b815468e5a86c1210652b3a19aece2720b;hpb=4f0463a079f61ca60ac94a126a5a9cd0f40c14f3;p=libsigrok.git diff --git a/src/strutil.c b/src/strutil.c index 30e992b8..5344ec29 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -67,6 +68,9 @@ SR_PRIV int sr_atol(const char *str, long *ret) errno = 0; tmp = strtol(str, &endptr, 10); + while (endptr && isspace(*endptr)) + endptr++; + if (!endptr || *endptr || errno) { if (!errno) errno = EINVAL; @@ -129,6 +133,9 @@ SR_PRIV int sr_atod(const char *str, double *ret) errno = 0; tmp = strtof(str, &endptr); + while (endptr && isspace(*endptr)) + endptr++; + if (!endptr || *endptr || errno) { if (!errno) errno = EINVAL; @@ -477,7 +484,8 @@ SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q) */ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) { - int multiplier, done; + uint64_t multiplier; + int done; double frac_part; char *s; @@ -504,6 +512,18 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) case 'G': multiplier = SR_GHZ(1); break; + case 't': + case 'T': + multiplier = SR_GHZ(1000); + break; + case 'p': + case 'P': + multiplier = SR_GHZ(1000 * 1000); + break; + case 'e': + case 'E': + multiplier = SR_GHZ(1000 * 1000 * 1000); + break; default: done = TRUE; s--; @@ -513,8 +533,9 @@ SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size) if (multiplier > 0) { *size *= multiplier; *size += frac_part * multiplier; - } else + } else { *size += frac_part; + } if (s && *s && g_ascii_strcasecmp(s, "Hz")) return SR_ERR;