Hi Bruno, On 2026-02-24T01:46:20+0100, Bruno Haible wrote: > Hi Alejandro, > > > Similar to strnul(3) returning a pointer, this stpspn(3) is a macro that > > returns a pointer instead of a length. > > Oh wait. Should we have called the new function stpnul() instead of strnul()? > Because it returns a pointer.
I've been rumiating similar questions about naming consistency for these
APIs. I think the conclusion for strnul(3) is not, because it doesn't
share ethimology with the size_t variant (strlen(3)). We have other
existing APIs that only have a variant that return an offset pointer,
and their name is str*(), strchr(3) being the canonical example.
stp*() would only be necessary where there's the two variants with the
same name.
>
> > The canonical implementation I have in shadow-utils is
> >
> > #define stpspn(s, accept) \
> > ({ \
> > __auto_type s_ = s; \
> > \
> > s_ + strspn(s_, accept); \
> > })
> >
> > but for gnulib I've implemented it similar to strnul(3). This macro
> > covers most uses of strspn(3)
>
> I agree that this macro is a nice-to-have, alongside with stpcspn().
>
> Previously one would have defined it as a function with return type 'char *',
> but that would have been ugly. With a const-generic macro, it's nicer.
Nice! :)
> > In replies to this cover letter, you'll find a patch that implements
> > stpspn(), and another patch that uses it in gnulib, to show how
> > beneficial it is.
>
> Please, let's finalize the strnul patches first. Not too many patch sets
> in parallel at the same time...
Makes sense. I'll bring back stpspn(3) in a couple of weeks or so.
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
