]> sigrok.org Git - libsigrok.git/blobdiff - src/strutil.c
strutil: accept trailing whitespace after number text
[libsigrok.git] / src / strutil.c
index 3fe59551bbf06776402b78071b1acdb4b24c6ab7..5344ec2903218bef4c7e9baabd3412d10b7929e5 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <config.h>
+#include <ctype.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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;