From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758683Ab1DNOGm (ORCPT ); Thu, 14 Apr 2011 10:06:42 -0400 Received: from mail-vx0-f174.google.com ([209.85.220.174]:64249 "EHLO mail-vx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754034Ab1DNOGl convert rfc822-to-8bit (ORCPT ); Thu, 14 Apr 2011 10:06:41 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=RrGYXUiU4aR5NevAO+ajjpMBiI4qlppiC8cQRh9NGJilhL0GrFUzz7EHbd47RnTtv/ /RnAE7NcsF71gRuEctj3Y1VurTaSvotROfQTDZhqKyEJMh4bwTb+u3xole8QvVYZkYlW YTy5mKDpp7zSaOXKJ8ishGKPG3lhzfcrD4vx4= MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 14 Apr 2011 17:06:34 +0300 Message-ID: Subject: Re: [PATCH] kstrtox: reuse functions from ctype.h From: Alexey Dobriyan To: Michal Nazarewicz Cc: Andrew Morton , linux-kernel@vger.kernel.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 14, 2011 at 4:34 PM, Michal Nazarewicz 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;