Re: [PATCH v8 02/10] lib: kstrtox: add kstrntoull() helper
From: David Laight
Date: Fri Mar 20 2026 - 10:59:17 EST
On Fri, 20 Mar 2026 12:41:57 +0000
Rodrigo Alencar <455.rodrigo.alencar@xxxxxxxxx> wrote:
...
> > Some (stupid) thoughts loudly. IIUC even if we implement '%g' in scanf(), it
> > wont help you as you want to have more precise values. Do I get it correct?
>
> If I am parsing 3.14159265359 with 6 decimal precision I want to stop at:
>
> frac = 141592
> int = 3
>
> and ignore the rest.
>
If you add an 'upper limit' parameter and return a pointer to the digit
that exceeds the limit (which would normally get processed as a syntax error)
then you could have:
int_part = strtoull(pi, &end, ~0ull, 10);
if (end[0] == '.' && isdigit(end[1])) {
frac = strtoull(end + 2, &end, 999999, 10);
while (isdigit(*end))
end++;
}
Passing in the limit should help strtol() are strtoi() as well.
David