]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/strutils: parse_size(), sync errno and return value
authorRuediger Meier <ruediger.meier@ga-group.nl>
Sun, 21 Feb 2016 15:18:04 +0000 (16:18 +0100)
committerRuediger Meier <ruediger.meier@ga-group.nl>
Sun, 21 Feb 2016 17:10:00 +0000 (18:10 +0100)
Maybe strtosize_or_err() is the only function which uses
this errno (wrongly). But it doesnt hurt to maintain rc
as well as errno.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
lib/strutils.c

index 03a367b9103b2cf395275f3838694755801a2842..64a6b992efd3026a414ccae37203af152a6c9de3 100644 (file)
@@ -91,7 +91,7 @@ int parse_size(const char *str, uintmax_t *res, int *power)
 
        if (p == str ||
            (errno != 0 && (x == UINTMAX_MAX || x == 0))) {
-               rc = errno ? -errno : -1;
+               rc = errno ? -errno : -EINVAL;
                goto err;
        }
        if (!p || !*p)
@@ -119,7 +119,7 @@ check_suffix:
                        frac = strtoumax(fstr, &p, 0);
                        if (p == fstr ||
                            (errno != 0 && (frac == UINTMAX_MAX || frac == 0))) {
-                               rc = errno ? -errno : -1;
+                               rc = errno ? -errno : -EINVAL;
                                goto err;
                        }
                        if (frac && (!p  || !*p)) {
@@ -164,6 +164,8 @@ check_suffix:
 done:
        *res = x;
 err:
+       if (rc < 0)
+               errno = -rc;
        return rc;
 }