Re: [PATCH v8 02/10] lib: kstrtox: add kstrntoull() helper
From: Rodrigo Alencar
Date: Wed Mar 04 2026 - 06:47:07 EST
On 26/03/04 10:16AM, David Laight wrote:
> On Tue, 03 Mar 2026 13:27:07 +0000
> Rodrigo Alencar via B4 Relay <devnull+rodrigo.alencar.analog.com@xxxxxxxxxx> wrote:
>
> > From: Rodrigo Alencar <rodrigo.alencar@xxxxxxxxxx>
> >
> > Add kstrntoull() function, which converts a string to an ULL with a max
> > character limit. The function is an alternative integer parsing function
> > that does not require a null-terminated string. It becomes a better option
> > over simple_strtoull() or kstrtoull() when parsing integers from a buffer
> > with custom delimiters without having to create temporary copies.
> > The function is consumed inside the implementation _kstrtoull(),
> > promoting reuse.
>
> If you've got custom delimiters use a function that returns a pointer
> to the character that terminated the conversion.
> They save you having to find the delimiter as well as taking a copy.
understood, how about this prototype then:
const char __must_check *kstrntoull(const char *s, unsigned int base,
unsigned long long *res, size_t max_chars);
to be used like:
end = kstrntoull(s, base, &res, INT_MAX);
if (IS_ERR(end)) {
/* return or handle error */
return PTR_ERR(end);
}
the name itself is still under discussion.
--
Kind regards,
Rodrigo Alencar