From: Linus Torvalds Date: Wed, 27 Apr 2011 08:37:17 GMT Subject: Re: [PATCHv3 5/6] Allow specifying --dirstat cut-off percentage as a floating point number Message-ID: In-Reply-To: <1303892653-3958-6-git-send-email-johan@herland.net> On Wed, Apr 27, 2011 at 1:24 AM, Johan Herland wrote: > +                       options->dirstat_permille = strtoul(p, &end, 10) * 10; >                        p = end; > +                       if (*p == '.' && isdigit(*(++p))) { > +                               int permille = strtoul(p, &end, 10); > +                               p = end; > +                               while (permille >= 10) > +                                       permille /= 10; /* only use first digit */ > +                               options->dirstat_permille += permille; > +                       } Heh. That's both unnecessarily complicated, and doesn't work. It gets the wrong answer for something like "0.0001", since 'permille' in that case ends up starting out as '0001', ie just 1, so you never actually do that whole while-loop. So the right approach is just something like if (*p == '.' && isdigit(*++p)) { /* only use first digit */ options->dirstat_permille += *p - '0'; /* .. and ignore any further digits */ while (isdigit(*++p)) /* nothing */; } (totally untested, of course) Linus