Re: [PATCH] kstrtox: reuse functions from ctype.h

From: Alexey Dobriyan
Date: Thu Apr 14 2011 - 10:06:46 EST


On Thu, Apr 14, 2011 at 4:34 PM, Michal Nazarewicz <mina86@xxxxxxxxxx> wrote:
> kstrto*() family of functions uses open coded test
> for a hexadecimal digit and

Yes, so?

> own implementation of tolower() function.

No!
It's special cased for this very usage, because the rest of ASCII is
of no concern.
It doesn't claim tolower() semantics.

> -                       if (_tolower(s[1]) == 'x' && isxdigit(s[2]))
> +                       if (tolower(s[1]) == 'x' && isxdigit(s[2]))
>                                base = 16;
>                        else
>                                base = 8;
>                } else
>                        base = 10;
>        }
> -       if (base == 16 && s[0] == '0' && _tolower(s[1]) == 'x')
> +       if (base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
>                s += 2;
>
>        acc = 0;
> @@ -47,8 +42,8 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
>
>                if ('0' <= *s && *s <= '9')
>                        val = *s - '0';
> -               else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f')
> -                       val = _tolower(*s) - 'a' + 10;
> +               else if (isxdigit(*s))

[0-9] are isxdigit() as well, so the code sort of logically duplicate.

> +                       val = tolower(*s) - 'a' + 10;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/